MCPcopy Index your code
hub / github.com/tortoise/tortoise-orm / run

Function run

examples/two_databases.py:57–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55
56
57async def run():
58 await Tortoise.init(
59 {
60 "connections": {
61 "first": {
62 "engine": "tortoise.backends.sqlite",
63 "credentials": {"file_path": "example.sqlite3"},
64 },
65 "second": {
66 "engine": "tortoise.backends.sqlite",
67 "credentials": {"file_path": "example1.sqlite3"},
68 },
69 },
70 "apps": {
71 "tournaments": {"models": ["__main__"], "default_connection": "first"},
72 "events": {"models": ["__main__"], "default_connection": "second"},
73 },
74 }
75 )
76 await Tortoise.generate_schemas()
77 client = connections.get("first")
78 second_client = connections.get("second")
79
80 tournament = await Tournament.create(name="Tournament")
81 await Event(name="Event", tournament_id=tournament.id).save()
82
83 try:
84 await client.execute_query('SELECT * FROM "event"')
85 except OperationalError:
86 print("Expected it to fail")
87 results = await second_client.execute_query('SELECT * FROM "event"')
88 print(results)
89
90
91if __name__ == "__main__":

Callers 1

two_databases.pyFile · 0.70

Calls 7

saveMethod · 0.80
EventClass · 0.70
initMethod · 0.45
generate_schemasMethod · 0.45
getMethod · 0.45
createMethod · 0.45
execute_queryMethod · 0.45

Tested by

no test coverage detected