A modest orm that does not require you to adjust your code to it
Project description
DBCore

ORM that does not require the developer to create models specifically for it. dbcore works with dataclasses and allows you to connect from one interface to both local databases (sqlite+aiosqlite) and remote databases (postgres+asyncpg).
Small example
import os
import asyncio
from dataclasses import dataclass
from aiodbcore import AsyncDBCore
# a model in which only the id field gives out DB membership
@dataclass
class MyModel:
id: int | None = None
foo: int = 0
bar: str = ""
class MyDB(AsyncDBCore[MyModel]):
# there i can implement my queries
async def my_simple_query(self) -> list[MyModel]:
return await self.fetchall(MyModel, where=MyModel.foo > 10)
async def main():
MyDB.init(os.environ["DB"]) # init db at start of program
db = MyDB()
data = await db.my_simple_query()
first = data[0]
first.foo += 100
await db.save(first)
await db.close_connections()
if __name__ == '__main__':
asyncio.run(main())
The declaration of the model from the example above is certainly simple and elegant, but this method does not allow the IDE to show type hints, and static typers will complain. Therefore, there is another way to declare models, it will require minimal changes in the code.
from dataclasses import dataclas
from aiodbcore.models import Field
@dataclass
class MyModel:
# Here you can wrap default values in `Field`
# if you don't want complaints from static typers,
# but it is not necessary
id: Field[int | None] = Field(None)
foo: Field[int] = 0
bar: Filed[str] = ""
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 aiodbcore-0.3.1.tar.gz.
File metadata
- Download URL: aiodbcore-0.3.1.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e884972b0e32a2945320e1f28454abb60c60f0b8dc191ff3c6292752268170b
|
|
| MD5 |
c9b6da469b1688dfd1bbde7a9abce682
|
|
| BLAKE2b-256 |
a2a02ee36ad6114947463f5e6243a498b32b5c0c5513bc6675c51d1cfc907915
|
File details
Details for the file aiodbcore-0.3.1-py3-none-any.whl.
File metadata
- Download URL: aiodbcore-0.3.1-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9796886dcb300e56d427778df5f3bd156af31ec04a5daa249991af1295dd9213
|
|
| MD5 |
ebc0aa85d15be6418c13920487df198d
|
|
| BLAKE2b-256 |
ca88981206722a59ba3e576e95a538e45b1ad1bc11aba5037efd1a8f864fc8c2
|