Skip to main content

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 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, pgsql

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;

Building

python -m build

Deploying

python -m twine upload --repository pypi dist/*

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

sb_db_common-0.0.6.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sb_db_common-0.0.6-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file sb_db_common-0.0.6.tar.gz.

File metadata

  • Download URL: sb_db_common-0.0.6.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for sb_db_common-0.0.6.tar.gz
Algorithm Hash digest
SHA256 40bf1b4f4dbc0e32e15637a93c67a0b952560b469dd3ece605746a29d4a6995d
MD5 954ac08c8d95638474a6f939e5c1ca6c
BLAKE2b-256 5d27ed8dabb58826a1ab99e366a8aa40d54692bc20887f592605ed02e521e0ab

See more details on using hashes here.

File details

Details for the file sb_db_common-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: sb_db_common-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for sb_db_common-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ac59cc365e7a719bff976e3353bb41e8dd1e484f68c3fe7651730f58a58e1ace
MD5 ae18e1af43b344f044f8d1ce756356a5
BLAKE2b-256 57bb385b7762736cf522738330eae8f8fb2068707ce279e901ce7e4ca85f571e

See more details on using hashes here.

Supported by

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