C{DBXS} (“database access”) is an asynchronous database access layer based on
Project description
DBXS: Simple Python Database Access
Sometimes, you just want to write SQL. No ORM, no expression language. SQL can be just fine. Plain SQL exposes a lot of features from your database engine which may not be expressible in a higher-level database abstraction.
But... you still don't want to allow for SQL injection. And you don't want the SQL smeared out, disorganized, in strings all over your codebase.
DBXS is a very lightweight system for organizing your queries into a
traditional data-access layer, using Python's built-in typing.Protocol
to
ensure that your database queries are type-safe, and requiring them to be
defined at module import time, so as to avoid the possibility of accidental
string formatting on your queries based on input.
Using it looks like this:
class Quote:
db: QuoteDB
id: int
contents: str
from dbxs import query, one, many
class QuoteDB(Protocol):
@query(
sql="select id, contents from quote where id = {id}",
load=one(Quote),
)
async def quoteByID(self, id: int) -> Quote:
...
@query(
sql="select id, contents from quote",
load=many(Quote),
)
def allQuotes(self) -> AsyncIterable[Quote]:
...
quotes = accessor(QuoteDB)
driver = adaptSynchronousDriver(lambda: sqlite3.connect(...))
async def main() -> None:
async with transaction(driver) as t:
quotedb: QuoteDB = quotes(t)
print("quote 1", (await quotedb.quoteByID(1)).contents)
async for quote in quotedb.allQuotes():
print("quote", quote.id, quote.contents)
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
Built Distribution
File details
Details for the file dbxs-0.0.4.tar.gz
.
File metadata
- Download URL: dbxs-0.0.4.tar.gz
- Upload date:
- Size: 28.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21ebdab05155b383a5c17de5a1eca0c99337ce8c944baf25e89e4f4cfc4ddc44 |
|
MD5 | 5293e00541c302a6ca4235ac08a366ad |
|
BLAKE2b-256 | eee396c79abdfb60017b414d74a7132492f8a08ad5fd2f35475046583d30fc82 |
File details
Details for the file dbxs-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: dbxs-0.0.4-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc161022d209a553608c63727556878b6be433ca72fa980f6b7943db3c6bdf84 |
|
MD5 | 8509948ad53232ddc5a655a0c04f5893 |
|
BLAKE2b-256 | 79f696dcbf231c51ce9502124b648ee5fc01d073fdd0c250e51ef011fe28791a |