This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
CircuitSacul edited this page Sep 26, 2022
·
3 revisions
DetaORM is a simple library designed to make working with Deta's Bases easier.
To the right, there is a list of pages providing details on different features of DetaORM. Below, you can find a basic example of how DetaORM is used.
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())
Feel free to contribute to this wiki; Just try to follow the general idea use for other pages. (Also make sure to add any pages you create to the sidebar.)