MCPcopy Create free account
hub / github.com/tortoise/tortoise-orm / run

Function run

examples/enum_fields.py:24–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22
23
24async def run():
25 await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]})
26 await Tortoise.generate_schemas()
27
28 obj0 = await EnumFields.create(service=Service.python_programming, currency=Currency.USD)
29 # also you can use valid int and str value directly
30 await EnumFields.create(service=1, currency="USD")
31
32 try:
33 # invalid enum value will raise ValueError
34 await EnumFields.create(service=4, currency="XXX")
35 except ValueError:
36 print("Value is invalid")
37
38 await EnumFields.filter(pk=obj0.pk).update(
39 service=Service.database_design, currency=Currency.HUF
40 )
41 # also you can use valid int and str value directly
42 await EnumFields.filter(pk=obj0.pk).update(service=2, currency="HUF")
43
44
45if __name__ == "__main__":

Callers 1

enum_fields.pyFile · 0.70

Calls 5

updateMethod · 0.80
initMethod · 0.45
generate_schemasMethod · 0.45
createMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected