To combine two tables from two separate MSSQL databases in Fastapi and SqlAlchemy, you can use the following method:
Create two SqlAlchemy engine objects with connection strings for each database.
Use the .table_names() method of each engine object to confirm the names of the tables in their respective databases.
Use the .reflect() method on each engine object to read all the table metadata for each database.
Create two SqlAlchemy metadata objects, and use the .merge() method to combine the table metadata for both databases.
Use the .session() method of the combined metadata object to create a new session.
Use the .query() method on this session to extract data from both tables as needed.
You can use JOIN queries or Union queries to join data from both tables.
The resulting combined data can then be used to generate responses for FastApi endpoints.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-01-02 11:00:00 +0000
Seen: 15 times
Last updated: Jun 05 '21
In PySpark, how does the lead function work when the value of a column changes?
How can SQL output be structured in a column-based XML format instead of row-based?
How can pgcrypto be used to secure data on Postgres?
What is the SQL grammar used for addSql in Doctrine?
How can Django Admin accommodate a variety of formats and locales for its input fields?
How can an array be passed using typo3 flexform xml and itemsProcConfig?