Skip to main content

Wraps SQL Syntax into a python API.

Project description

dbwrapper

Note: this library is pre-alpha.

This version of dbwrapper is highly subject to change. Due to this, I won't be documenting a lot of the API. I tried to make the code fairly readable and code-suggestion friendly. I'm not planning on changing the structure of the major classes, but function arguments will definitely change and features will definitely be removed or addded.

dbwrapper is a lightweight python library designed to simplify interacting with databases of all kinds. This is not an ORM, and I have no plans to make it one. dbwrapper allows programmers to easily create queries using a fluent API. The primary focus of this library is to make data persistance database-agnostic while keeping query overhead low.

Supported Databases

  • SQLite
  • PostgreSQL

Databases with planned support

  • SQL Server
  • MySQL
  • MongoDB

Features

  • SELECT, UPDATE, INSERT, DELETE statements
  • Table Creation (via a Builder)
  • Migrations
    • Note: Migrations are not automatically created, you have full control over these!
  • List Tables
  • List Table Columns
  • 'Type Safe' Table and Column retreival
    • Only the presence of tables & columns is validated. Verifying the datatype would incur too much overhead.
  • Aliasing for Tables and Columns
  • SQL Functions (partially implemented)
  • Connection Pooling
  • Built in logging and query profiling (just enable it using logging.basicConfig)

Simple Example Usage

from dbwrapper import sqlite # or postgresql

# If using PostgreSQL, the connection string will need to be changed
connection = sqlite.Connection("data.db")

db = connection.database(sqlite.MASTER_DB)

if "test" not in db.tables:
    with db.table("test").builder() as builder:
        builder.column("id", db.dtypes.integer)
        builder.column("a", db.dtypes.varchar)
        builder.column("b", db.dtypes.float)

        builder.primary_key("id", autoincrement=True)

test = db.tables.test

test.delete().execute() # delete everthing

for i in range(5):
    test.insert_one({
        test.columns.a: "hello world!",
        test.columns.b: i / 5
    })

# no parameters for select() = all columns
results = test.select(
        test.columns.id,
        test.columns.a,
        test.columns.b
    ) \
    .where(test.columns.b <= 0.5) \
    .execute()

print(results)

connection.close() # optional, but good practice

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbwrapper-python-0.1.1.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

dbwrapper_python-0.1.1-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file dbwrapper-python-0.1.1.tar.gz.

File metadata

  • Download URL: dbwrapper-python-0.1.1.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

File hashes

Hashes for dbwrapper-python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 74c9aea0a917dff663f1554ccd9800a6ce61f7ed51766cb87eb6b0d41977e487
MD5 770d2cd206c48dc26d8434df7cdcf97e
BLAKE2b-256 071e9fa4bffe7434093869537a82f0560e1da04b406f85928c5bbae8d2fe63de

See more details on using hashes here.

File details

Details for the file dbwrapper_python-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dbwrapper_python-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

File hashes

Hashes for dbwrapper_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2b8b975eadd6b9869037bc5203c3d5d45676b763a5256a1d3c9091257ff84084
MD5 8afc8c477e491b96555f11a2a8dd127f
BLAKE2b-256 07f2aa88d40ac510ea634f26f73436ea818ca3da4bf4c04d7685771a9182896b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page