MCPcopy
hub / github.com/tortoise/tortoise-orm / run

Function run

examples/pydantic/tutorial_2.py:36–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34
35
36async def run():
37 await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]})
38 await Tortoise.generate_schemas()
39
40 # Create objects
41 await Tournament.create(name="New Tournament")
42 await Tournament.create(name="Another")
43 await Tournament.create(name="Last Tournament")
44
45 # Serialise it
46 tourpy = await Tournament_Pydantic_List.from_queryset(Tournament.all())
47
48 # As Python dict with Python objects (e.g. datetime)
49 # Note that the root element is 'root' that contains the root element.
50 print(tourpy.model_dump())
51 # As serialised JSON (e.g. datetime is ISO8601 string representation)
52 print(tourpy.model_dump_json(indent=4))
53
54
55if __name__ == "__main__":

Callers 1

tutorial_2.pyFile · 0.70

Calls 5

initMethod · 0.45
generate_schemasMethod · 0.45
createMethod · 0.45
from_querysetMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected