Custom Database Queries
Project description
Few Utility Functions
Install
pip install ddcDatabases
Databases
DBSQLITE
class DBSqlite(db_file_path: str, batch_size=100, echo=False, future=True)
import sqlalchemy as sa
from ddcDatabases import DBSqlite, DBUtils
dbsqlite = DBSqlite(database_file_path)
with dbsqlite.session() as session:
stmt = sa.select(Table).where(Table.id == 1)
db_utils = DBUtils(session)
results = db_utils.fetchall(stmt)
DBPOSTGRES
- Using driver "psycopg2" as default
class DBPostgres(future=True, echo=False, drivername="psycopg2", **kwargs)
import sqlalchemy as sa
from ddcDatabases import DBPostgres, DBUtils
db_configs = {
"username": username,
"password": password,
"host": host,
"port": port,
"database": database
}
dbpostgres = DBPostgres(**db_configs)
with dbpostgres.session() as session:
stmt = sa.select(Table).where(Table.id == 1)
db_utils = DBUtils(session)
results = db_utils.fetchall(stmt)
- DBUTILS
- Uses SQLAlchemy statements
from ddcDatabases import DBUtils
db_utils = DBUtils(session)
db_utils.add(stmt)
db_utils.execute(stmt)
db_utils.fetchall(stmt)
db_utils.fetchone(stmt)
db_utils.fetch_value(stmt)
DBPOSTGRES ASYNC
- Using driver "asyncpg"
class DBPostgresAsync(future=True, echo=False, drivername="asyncpg", **kwargs)
import sqlalchemy as sa
from ddcDatabases import DBPostgresAsync, DBUtilsAsync
db_configs = {
"username": username,
"password": password,
"host": host,
"port": port,
"database": database
}
dbpostgres = DBPostgresAsync(**db_configs)
async with dbpostgres.session() as session:
stmt = sa.select(Table).where(Table.id == 1)
db_utils = DBUtilsAsync(session)
results = await db_utils.fetchall(stmt)
- DBUTILS ASYNC
- Uses SQLAlchemy statements
from ddcDatabases import DBUtilsAsync
db_utils = DBUtilsAsync(session)
await db_utils.add(stmt)
await db_utils.execute(stmt)
await db_utils.fetchall(stmt)
await db_utils.fetchone(stmt)
await db_utils.fetch_value(stmt)
Source Code
Build
poetry build
Run Tests
poetry run coverage run -m pytest -v
Get Coverage Report
poetry run coverage report
License
Released under the MIT License
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
ddcdatabases-1.0.7.tar.gz
(4.8 kB
view details)
Built Distribution
File details
Details for the file ddcdatabases-1.0.7.tar.gz
.
File metadata
- Download URL: ddcdatabases-1.0.7.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7dff4ab84d2324b1e32e11c02698dab13c8ab0ae2183578b418da01c2d61b35 |
|
MD5 | eca5ffb70bcff8da390da41a8a481805 |
|
BLAKE2b-256 | 17c3f41ba8e2c4e0743b6ca657fe5dc933960a735a985bd9fbb2080b94dea60d |
File details
Details for the file ddcdatabases-1.0.7-py3-none-any.whl
.
File metadata
- Download URL: ddcdatabases-1.0.7-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0d4c379e3680930da99dd4338e57b1692d6ac29cf087854733b9b3def7e049a |
|
MD5 | 1a967a52c833ca736efc0cb0ddc3ad73 |
|
BLAKE2b-256 | 872b454cd3245d0cc044aecae0883932173b633d0e4f28c0faa7cd8b210ac6d3 |