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
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
ddcdatabases-1.0.6.tar.gz
(4.8 kB
view details)
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 ddcdatabases-1.0.6.tar.gz.
File metadata
- Download URL: ddcdatabases-1.0.6.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79f0cba30b88f8bda8c4d524cd09da471993b719ed4612a5fb2e8c614e83ec29
|
|
| MD5 |
5759933b64aeb3050177d3fed297c9ec
|
|
| BLAKE2b-256 |
b88638acc4a89732bcb9fbb99c6862f387a8e730389fab7bfca87c2f03747f33
|
File details
Details for the file ddcdatabases-1.0.6-py3-none-any.whl.
File metadata
- Download URL: ddcdatabases-1.0.6-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.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d60074c998cce393e2334be8cf3e855fef279ecdde02d09c257e1e8ce3908bd
|
|
| MD5 |
82ceafc3be2dab03e5754f0ef134b54a
|
|
| BLAKE2b-256 |
34582ff23b9a843e7d2eae397dcb71286b5352fc6e00f10810cd634161405018
|