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.4.tar.gz (21.3 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.4-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: classic_db_tools-0.0.4.tar.gz
  • Upload date:
  • Size: 21.3 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.4.tar.gz
Algorithm Hash digest
SHA256 a49185799dc8909798940d5df9cfc2d904cb6712eaeb58f4585adaf33de39fd8
MD5 c46c0a0d83efa84aa6efb2f8d0b1a80c
BLAKE2b-256 768d08dd2e896f8b6e8ce2a684944b1cea267db54b7528f6320079a3d3a2409e

See more details on using hashes here.

Provenance

The following attestation bundles were made for classic_db_tools-0.0.4.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.4-py3-none-any.whl.

File metadata

File hashes

Hashes for classic_db_tools-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0f4cf8c786c55ad50e9f3eeebfcda046664bddb26cad5f85a7606f440ab21987
MD5 61138896e1aa7f836c8634c4dfbb196a
BLAKE2b-256 4815796bd974c7baa1e4ab8c2ec27fe767b506ff284eac38502b7b3b285f1ff4

See more details on using hashes here.

Provenance

The following attestation bundles were made for classic_db_tools-0.0.4-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