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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dbwrapper_python-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b8b975eadd6b9869037bc5203c3d5d45676b763a5256a1d3c9091257ff84084 |
|
MD5 | 8afc8c477e491b96555f11a2a8dd127f |
|
BLAKE2b-256 | 07f2aa88d40ac510ea634f26f73436ea818ca3da4bf4c04d7685771a9182896b |