The light Python DB API wrapper with some ORM functions (MySQL, PostgreSQL, SQLite)
Quick start (run demo files)
- in docker:
git clone https://github.com/AndreiPuchko/zzdb && cd zzdb/database.docker
./up.sh
./down.sh
- on your system:
pip install zzdb
git clone https://github.com/AndreiPuchko/zzdb && cd zzdb
# sqlite:
python3 ./demo/demo.py
# mysql and postgresql:
pip install mysql-connector-python psycopg2-binary
pushd database.docker && docker-compose up -d && popd
python3 ./demo/demo_mysql.py
python3 ./demo/demo_postgresql.py
pushd database.docker && docker-compose down -v && popd
Features:
Connect
from zzdb.db import ZzDb
database_sqlite = ZzDb("sqlite3", database_name=":memory:")
# or just
database_sqlite = ZzDb()
database_mysql = ZzDb(
"mysql",
user="root",
password="zztest"
host="0.0.0.0",
port="3308",
database_name="zztest",
)
# or just
database_mysql = ZzDb(url="mysql://root:zztest@0.0.0.0:3308/zztest")
database_postgresql = ZzDb(
"postgresql",
user="zzuser",
password="zztest"
host="0.0.0.0",
port=5432,
database_name="zztest1",
)
Define & migrate database schema (ADD COLUMN only).
zzdb.schema import ZzDbSchema
schema = ZzDbSchema()
schema.add(table="topic_table", column="uid", datatype="int", datalen=9, pk=True)
schema.add(table="topic_table", column="name", datatype="varchar", datalen=100)
schema.add(table="message_table", column="uid", datatype="int", datalen=9, pk=True)
schema.add(table="message_table", column="message", datatype="varchar", datalen=100)
schema.add(
table="message_table",
column="parent_uid",
to_table="topic_table",
to_column="uid",
related="name"
)
database.set_schema(schema)
INSERT, UPDATE, DELETE
database.insert("topic_table", {"name": "topic 0"})
database.insert("topic_table", {"name": "topic 1"})
database.insert("topic_table", {"name": "topic 2"})
database.insert("topic_table", {"name": "topic 3"})
database.insert("message_table", {"message": "Message 0 in 0", "parent_uid": 0})
database.insert("message_table", {"message": "Message 1 in 0", "parent_uid": 0})
database.insert("message_table", {"message": "Message 0 in 1", "parent_uid": 1})
database.insert("message_table", {"message": "Message 1 in 1", "parent_uid": 1})
# this returns False because there is no value 2 in topic_table.id - schema works!
database.insert("message_table", {"message": "Message 1 in 1", "parent_uid": 2})
database.delete("message_table", {"uid": 2})
database.update("message_table", {"uid": 0, "message": "updated message"})
Cursor
cursor = database.cursor(table_name="topic_table")
cursor = database.cursor(
table_name="topic_table",
where=" name like '%2%'",
order="name desc"
)
cursor.insert({"name": "insert record via cursor"})
cursor.delete({"uid": 2})
cursor.update({"uid": 0, "message": "updated message"})
cursor = database.cursor(sql="select name from topic_table")
for x in cursor.records():
print(x)
print(cursor.r.name)
cursor.record(0)['name']
cursor.row_count()
cursor.first()
cursor.last()
cursor.next()
cursor.prev()
cursor.bof()
cursor.eof()
Metadata
Release files for zzdb 0.1.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zzdb-0.1.11.tar.gz | 18.6 kB | Without provenance | Details for zzdb-0.1.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zzdb-0.1.11-py3-none-any.whl | Python 3 | none | any | Details for zzdb-0.1.11-py3-none-any.whl |
Total release size: 38.2 kB
Release files / zzdb-0.1.11.tar.gz
| Download URL | zzdb-0.1.11.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e8de547f628cebae86d788d82f25ee1e755851e47df96e403b92ed6fc590375
|
|
BLAKE2b-256 checksum How to use checksums |
0bc66b78bb7f79114e41e02a4787c72fe3be041ebd02d5b4e7de8ebf398e26b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.9.5 Linux/5.11.0-49-generic
|
Release files / zzdb-0.1.11-py3-none-any.whl
| Download URL | zzdb-0.1.11-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c81dc112b2a4b53fde963067486249823713f235b1dce97539dffd0d638d7598
|
|
BLAKE2b-256 checksum How to use checksums |
2d43f94d03c090151c3f404be4f1d06466d33918cf9f1e0cb1366bcbb08fdf02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.9.5 Linux/5.11.0-49-generic
|
Security for zzdb 0.1.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.