A set of db wrappers
Project description
Db Common Lib
Mainly for myself, switching between different database providers all the time, I wanted a consistent interface.
Thats what this is for.
More consistent (Think ADO.NET) db connectivity
Overview
Links psgsql, mysql, mssql and sqlite in a common interface
Unit tests provided to show usage
Usage
Connection string format is: <provider>://<username>:<password>@<host>/<database>
The supported providers are:
sqlite, mysql, mssql, pgsql
The providers self-register. Call SessionFactory.register() before use.
with SessionFactory.connect(<connection string>) as session:
id = session.execute_lastrowid("insert into test(name) values (:name);", {"name": "bob"})
session.execute("update test set name = :name where id = :id", {"id": id, "name": "bob1"})
The session closes and commits automatically when it goes out of scope.
For more control, manually call commit and rollback.
The queries are db specific, but the mechanisms are the same for all.
Major differences are the different field types, the parameter specification and in the use of identity columns across the different db's.
Remember to add returning <field> to the insert statement for pgsql or you won't get the identity back.
Differences
sqlite
CREATE TABLE test(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT
);
INSERT INTO test(name) VALUES (:name)
mysql
CREATE TABLE test(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NULL
);
INSERT INTO test(name) VALUES (%(name)s);
pgsql
CREATE TABLE test(
id INT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name VARCHAR(50) NULL
);
INSERT INTO test(name) VALUES (%(name)s) RETURNING id;
mssql
Integrated security is supported, either by passing in a windows username / password, or by setting trusted_connection=yes and passing in a dummy username / password. It will use the current logged in user.
Building
python -m build
Deploying
python -m twine upload --repository pypi dist/*
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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sb_db_common-0.0.8-py3-none-any.whl.
File metadata
- Download URL: sb_db_common-0.0.8-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99e8e98a78017f21dd8caff46f03f74c689b15f94cfa72e55a4cd547824273ee
|
|
| MD5 |
7f500c5a069ebb89595151e98b2dad81
|
|
| BLAKE2b-256 |
a3c8768fb815686cf79d61afebb209f0f869434ab5b27ffe8aacb86ddb771306
|