Skip to main content

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

Project description

DBCore Python 3.12+ License:MIT PyPi version

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] = ""

Sync version

SyncDBCore has the same interface as the async version. You just need to remove all the async and await statements.

class MyDB(SyncDBCore[MyModel]):  # the same model `MyModel` is used
    def my_simple_query(self) -> list[MyModel]:
        return self.fetchall(MyModel, where=MyModel.foo > 10)

Currently only sqlite+sqlite3 is supported.

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

aiodbcore-0.5.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

aiodbcore-0.5.0-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file aiodbcore-0.5.0.tar.gz.

File metadata

  • Download URL: aiodbcore-0.5.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiodbcore-0.5.0.tar.gz
Algorithm Hash digest
SHA256 7461fec04f9217bef30bc7c2d2a9be6c2561736532def09380e46b17724cd161
MD5 16a2adf743622384a1cc7a8c4ad1885e
BLAKE2b-256 9f84b70aa0647ccdeb80c14cd25c2e81a87e60a6213a57e0461b26086f9eb384

See more details on using hashes here.

File details

Details for the file aiodbcore-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: aiodbcore-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiodbcore-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd4120daf9708127e36dd432a08a38f16b47fb5875c9132c2d5141a9c44b1d9c
MD5 b5eb7e1ba227c38a26ccc9c185d7cc62
BLAKE2b-256 e41226d5e44704f08b8e08966149787a710b1626c1a4828a92612592f08456d1

See more details on using hashes here.

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