Skip to main content

Python application

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()

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zzdb-0.1.4.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

zzdb-0.1.4-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file zzdb-0.1.4.tar.gz.

File metadata

  • Download URL: zzdb-0.1.4.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.5 Linux/5.11.0-40-generic

File hashes

Hashes for zzdb-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c96b51e591323bb0e297fffddd44bb2f1c4fb16b3babb525b0dd81f56fe31c7d
MD5 23405c601b40f80cd03cf117e07ec995
BLAKE2b-256 c55ac3f255059649bccae632e04eb4cc4c8b71bed9a8e5df82258353ff6416cc

See more details on using hashes here.

File details

Details for the file zzdb-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: zzdb-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.5 Linux/5.11.0-40-generic

File hashes

Hashes for zzdb-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6c03bfd822ebc02b40b3f7f3af6c068a2f12e9153ca3e0161a8f9a625b485701
MD5 a97ed6597d4cbfa49c0d3506305ae47a
BLAKE2b-256 2729c82298cb60fce354471958b66b363b1d4424c909cf705476fcad7b9e1a78

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

This release

0.1.4 This release

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page