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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc1c9f76750a6eb7411c527164323992cb4acce6908584ae20b6a8b9e0d2e85b
|
|
| MD5 |
96be87a972f2eea08eeebb4c5cc1487a
|
|
| BLAKE2b-256 |
fc0f29786f45241b27ed280d60163784b31886a5e431f8f6f1aea8a257474a86
|
Provenance
The following attestation bundles were made for classic_db_tools-0.0.3.tar.gz:
Publisher:
publish.yml on variasov/classic-db-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
classic_db_tools-0.0.3.tar.gz -
Subject digest:
dc1c9f76750a6eb7411c527164323992cb4acce6908584ae20b6a8b9e0d2e85b - Sigstore transparency entry: 629277384
- Sigstore integration time:
-
Permalink:
variasov/classic-db-tools@4e19744621f8285d7836431e57602060af0306fd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/variasov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4e19744621f8285d7836431e57602060af0306fd -
Trigger Event:
push
-
Statement type:
File details
Details for the file classic_db_tools-0.0.3-py3-none-any.whl.
File metadata
- Download URL: classic_db_tools-0.0.3-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9df3bbe61dca7eb8d4744b34b2f57af23869af3896b62e7452f497b7d5cf49c
|
|
| MD5 |
ee1d94f0020de19fae41f39073d4b324
|
|
| BLAKE2b-256 |
3b92a299db9400460ec5cd081353d2e3ca07fa79f1b476050cd3cfb0d1ecc12d
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
classic_db_tools-0.0.3-py3-none-any.whl -
Subject digest:
d9df3bbe61dca7eb8d4744b34b2f57af23869af3896b62e7452f497b7d5cf49c - Sigstore transparency entry: 629277396
- Sigstore integration time:
-
Permalink:
variasov/classic-db-tools@4e19744621f8285d7836431e57602060af0306fd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/variasov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4e19744621f8285d7836431e57602060af0306fd -
Trigger Event:
push
-
Statement type: