This project/library contains common elements and clients related to database engines...
Project description
core-db
This project/library contains common elements related to database engines and provides clients to simplify the connections...
Execution Environment
Install libraries
pip install --upgrade pip
pip install virtualenv
Create the Python Virtual Environment.
virtualenv --python=python3.11 .venv
Activate the Virtual Environment.
source .venv/bin/activate
Install required libraries.
pip install .
Optional libraries.
pip install '.[all]' # For all...
pip install '.[mysql]'
pip install '.[postgre]'
pip install '.[oracle]'
pip install '.[mongo]'
pip install '.[mssql]'
pip install '.[snowflake]'
pip install '.[db2]'
Check tests and coverage...
python manager.py run-tests
python manager.py run-coverage
Clients
Postgres
from core_db.engines.postgres import PostgresClient
with PostgresClient(conninfo=f"postgresql://postgres:postgres@localhost:5432/test") as client:
client.execute("SELECT version() AS version;")
print(client.fetch_one()[0])
Mongo
from core_db.engines.mongo import MongoClient
client = MongoClient(**{"host": "host", "database": "db"})
client.connect()
print(client.test_connection())
MsSql
from core_db.engines.mssql import MsSqlClient
with MsSqlClient(
dsn="DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost;DATABASE=master;UID=SA;PWD=sOm3str0ngP@33w0rd;Encrypt=no",
autocommit=True, timeout=5) as client:
client.execute("SELECT @@VERSION AS 'version';")
print(list(client.fetch_records()))
Oracle
from core_db.engines.oracle import OracleClient
with OracleClient(user="...", password="...", dsn=f"{host}:{port}/{service_name}") as client:
res = client.execute("SELECT * FROM ...")
for x in client.fetch_all():
print(x)
MySQL
from core_db.engines.mysql import MySQLClient
with MySQLClient(host="localhost", user="root", password="SomePassword") as client:
client.execute("SELECT * FROM ...;")
for x in client.fetch_all():
print(x)
Snowflake
...
Testing clients...
We can test the clients by executing the below command. It will perform a series of query execution in the database engine to ensure it's working as expected. We must have the database engine up and running...
Example PostgreSQL:
docker run --env=POSTGRES_PASSWORD=postgres --env=PGDATA=/var/lib/postgresql/data --volume=/var/lib/postgresql/data -p 5432:5432 -d postgres:12.18-bullseye
python manager.py run-database-test -db PostgresClient -params '{"conninfo":"postgresql://postgres:postgres@localhost:5432/postgres"}'
Example MySQL:
docker run --env=MYSQL_ROOT_PASSWORD=mysql_password --volume=/var/lib/mysql -p 3306:3306 --restart=no --runtime=runc -d mysql:latest
python manager.py run-database-test -db MySQLClient -params '{"host": "localhost", "database": "sys", "user": "root", "password": "mysql_password"}'
Example Oracle:
docker pull container-registry.oracle.com/database/express:latest
docker container create -it --name OracleSQL -p 1521:1521 -e ORACLE_PWD=oracle_password container-registry.oracle.com/database/express:latest
docker start OracleSQL
python manager.py run-database-test -db OracleClient -params '{"user": "SYSTEM", "password": "oracle_password", "dsn": "localhost:1521/xe"}'
Example MsSQL:
docker pull mcr.microsoft.com/mssql/server:2022-latest
docker run\
-e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=sOm3str0ngP@33w0rd" \
-p 1433:1433 --name MsSQL --hostname MsSQL \
-d \
mcr.microsoft.com/mssql/server:2022-latest
docker start MsSQL
sudo /bin/bash ./scripts/install_mssql_driver.sh
python manager.py run-database-test -db MsSqlClient -params '{"dsn": "DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost;DATABASE=master;UID=SA;PWD=sOm3str0ngP@33w0rd;Encrypt=no"}'
Example DB2:
curl https://public.dhe.ibm.com/software/ibmi/products/odbc/debs/dists/1.1.0/ibmi-acs-1.1.0.list | sudo tee /etc/apt/sources.list.d/ibmi-acs-1.1.0.list
sudo apt update
sudo apt install ibm-iaccess
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
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 core_db-2.0.4.tar.gz.
File metadata
- Download URL: core_db-2.0.4.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e73d40bbd6276dc96a9d93fa71ef3603e795dec6227202b06676f7259daf666a
|
|
| MD5 |
5f132497e0bd78bcf5d0606f6495db0a
|
|
| BLAKE2b-256 |
da8b11977d5acc408a5a6b0bbd53aa039db19eb782c287ed90e04b52d94a390a
|
File details
Details for the file core_db-2.0.4-py3-none-any.whl.
File metadata
- Download URL: core_db-2.0.4-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
276bdb83b205bb6b6836db589f91dfa136271cb3cb62153a5c61b7894fcd74cc
|
|
| MD5 |
8cc9daf529aed6089d2bfe0e38228efe
|
|
| BLAKE2b-256 |
1a93b70a077f4c9ee5d8d2e9ef71b41ead55f52edde320f038fdf5dcb6ca669e
|