Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Latest commit

 

History

History
38 lines (25 loc) · 1.19 KB

README.md

File metadata and controls

38 lines (25 loc) · 1.19 KB

DetaORM

An async ORM for DetaBase.

Support | PyPI | Documentation

Example Usage

from __future__ import annotations

import asyncio

from detaorm import Client, Base, Field


class User(Base, name="users"):
    username: Field[str] = Field()
    nicknames: Field[list[str]] = Field(default=[])


async def main() -> None:
    client = Client("<project key>", bases=[User])
    await client.open()

    new_user = User(username="CircuitSacul")
    print(new_user)  # > User({"username": "CircuitSacul"})
    inserted_user = await new_user.insert()
    print(inserted_user)   # > User({"username": "CircuitSacul", "nicknames": []})

    updated_user = await inserted_user.update(User.nicknames.append(["Circuit", "Sacul"]))
    print(updated_user)  # > User({"username": "CircuitSacul", "nicknames": ["Circuit", "Sacul"]})

    page = await User.where(User.nicknames.contains("Sacul"), limit=1)
    print(page.items[0])  # > User({"username": "CircuitSacul", "nicknames": ["Circuit", "Sacul"]})


if __name__ == "__main__":
    asyncio.run(main())