Repository navigation
Help:How to use dual data sources (such as MySQL and pgSQL) simultaneously while using fastAPI with tortoise-orm #1678
Unanswered
CodeDan-CN
asked this question in
Q&A
Replies: 1 comment
|
Tortoise supports several connections in one await Tortoise.init(config={
"connections": {
"default": "mysql://user:pass@localhost:3306/main",
"pg": "postgres://user:pass@localhost:5432/other",
},
"apps": {
"main": {"models": ["app.models"], "default_connection": "default"},
"pg": {"models": ["app.pg_models"], "default_connection": "pg"},
},
})Set For Postgres tables you haven't modelled, use the connection directly: from tortoise import connections
rows = await connections.get("pg").execute_query_dict("SELECT id, label FROM report WHERE id = $1", [1])Two things to watch:
I checked this with tortoise-orm 1.1.9, using two SQLite databases in place of MySQL and Postgres. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The data is stored in MySQL, but sometimes it is necessary to connect to pgSQL and use the data from the pgSQL database
All reactions