0

I wanted to connect multiple databases. I tried to go through the https://github.com/tiangolo/fastapi/issues/2592 but was unable to understand the approach. How can I get data using this function

`@router.get('/')
def get(self, session: Session = Depends(get_session)):
    pass`

I'm only fetch data from one database using this function:

@router.get('/')
def read_users(db:Session = Depends(get_session)):
    data = db.query(ModelDB1).all()
    return data

I was also curious as to how will I be able to fetch data from the database and also update the values in the database. It will be great if anyone can help me out, also are there any other examples or methods which would do the job?

1
  • 1
    If you want to have multiple connections, you have to provide SQLAlchemy with information about which connection to use for which models. You can see how you do that in the comment that binds them to different models: github.com/tiangolo/fastapi/issues/2592#issuecomment-773208039 - What about this technique is it that doesn't work as you expect? Commented Nov 3, 2022 at 12:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.