Skip to content

theori-io/aiosqlite-strict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aiosqlite-strict

Strict Pydantic models on top of aiosqlite.

Install

pip install aiosqlite-strict

Usage

import asyncio

import aiosqlite
from aiosqlite_strict import TableModel

class AppTable(TableModel):
    ...

class User(AppTable):
    __indices__ = [("name",)]

    name: str
    email: str

async def main() -> None:
    async with aiosqlite.connect(":memory:") as db:
        await AppTable.sqlite_init(db)

        user1 = await User.create(db, name="name1", email="email1")
        _ = await User.create(db, name="name2", email="email2")

        async with User.select(db) as cursor:
            print(await cursor.fetchall())

        await user1.update_one(db, name="name1.1")

        async with User.select(db, "WHERE name=?", ("name1.1",)) as cursor:
            print(await cursor.fetchall())

asyncio.run(main())

Development

uv run pytest

About

aiosqlite + pydantic

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages