Skip to main content

Classic DB tools

Project description

Classic DB Tools

Идея библиотеки заключается в попытке работать с SQL-запросами как с шаблонами Jinja. Вдохновлено embrace и jinjasql, оттуда же бралась часть кода.

Установка:

pip install classic-db-tools

Quickstart:

from classic.db_tools import Engine, ConnectionPool
import psycopg

pool = ConnectionPool(psycopg.connect)
engine = Engine('path/to/sql/templates/dir', pool)

# При входе движок займет соединение в пуле,
# на выходе, по дефолту, закоммитит
with engine:
    # Применим схему:
    engine.query_from('tasks/ddl.sql').execute()

    # Сохранение данных
    engine.query_from('tasks/save.sql').executemany([
        {'title': 'Some Task', 'body': 'Do something'},
        {'title': 'Another Task', 'body': 'Do anything'},
    ])

    # Получение данных
    task = engine.query_from('tasks/get_by_id.sql').one(id=1)
    # (1, 'Some Task', 'Do something')

В директории sql рядом с .py файлом надо разместить 3 файла (можно найти в директории test/example):

sql/tasks/ddl.sql:

CREATE TABLE tasks (
    id serial PRIMARY KEY,
    title text,
    body text
);

sql/tasks/get_by_id.sql:

SELECT id, title, body FROM tasks WHERE id = %(id)s;

sql/tasks/save.sql:

INSERT INTO tasks (title, body) VALUES (%(title)s, %(body)s);

Возможности

Управление коннектом и транзакциями

Выполнение из файла и напрямую

Статические запросы

Динамические запросы

Выдача значений

Маппинг

Маппинг на классы

Маппинг на словари

Кастомные идентификаторы

Композитные ключи

Отложенные операции

ScopedConnection

Transaction

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

classic_db_tools-0.0.3.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

classic_db_tools-0.0.3-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file classic_db_tools-0.0.3.tar.gz.

File metadata

  • Download URL: classic_db_tools-0.0.3.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for classic_db_tools-0.0.3.tar.gz
Algorithm Hash digest
SHA256 dc1c9f76750a6eb7411c527164323992cb4acce6908584ae20b6a8b9e0d2e85b
MD5 96be87a972f2eea08eeebb4c5cc1487a
BLAKE2b-256 fc0f29786f45241b27ed280d60163784b31886a5e431f8f6f1aea8a257474a86

See more details on using hashes here.

Provenance

The following attestation bundles were made for classic_db_tools-0.0.3.tar.gz:

Publisher: publish.yml on variasov/classic-db-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file classic_db_tools-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for classic_db_tools-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d9df3bbe61dca7eb8d4744b34b2f57af23869af3896b62e7452f497b7d5cf49c
MD5 ee1d94f0020de19fae41f39073d4b324
BLAKE2b-256 3b92a299db9400460ec5cd081353d2e3ca07fa79f1b476050cd3cfb0d1ecc12d

See more details on using hashes here.

Provenance

The following attestation bundles were made for classic_db_tools-0.0.3-py3-none-any.whl:

Publisher: publish.yml on variasov/classic-db-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page