You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromormicimportDatabase, Modeldb=Database()
# create a model@db.modelclassPoint(Model):
name: strx: inty: int=5# default value# connect to a databaseawaitdb.connect("database.db")
Database Actions
# create an objectpoint=Point(name="A", x=5, y=10)
awaitpoint.save()
# fetch objects from the databasepoint_named_A: Point|None=awaitPoint.fetch(name="A")
list_of_points_named_A: list[Point] |None=awaitPoint.fetch_all(name="A")
# update an objectawaitpoint.update(y=15)
# orpoint.y=15awaitpoint.update()
# delete an objectawaitpoint.delete()
Caching
# turn caching on# setting limit to 20 will only cache the last fetched 20 objects# this parameter defaults to None, caching all fetched objectsdatabase.set_caching(on=True, limit=20)
# get the object from the cache# will fetch from the database if no matches foundpoint_named_A=awaitPoint.get_or_fetch(name="A")