Ask Your Question
3

What is the method for combining two tables from two separate MSSQL databases in Fastapi and SqlAlchemy?

asked 2022-01-02 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-06-05 23:00:00 +0000

ladyg gravatar image

To combine two tables from two separate MSSQL databases in Fastapi and SqlAlchemy, you can use the following method:

  1. Create two SqlAlchemy engine objects with connection strings for each database.

  2. Use the .table_names() method of each engine object to confirm the names of the tables in their respective databases.

  3. Use the .reflect() method on each engine object to read all the table metadata for each database.

  4. Create two SqlAlchemy metadata objects, and use the .merge() method to combine the table metadata for both databases.

  5. Use the .session() method of the combined metadata object to create a new session.

  6. Use the .query() method on this session to extract data from both tables as needed.

  7. 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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2022-01-02 11:00:00 +0000

Seen: 15 times

Last updated: Jun 05 '21