Skip to content

Create Database Connection Management #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 2 tasks
CDiezRodriguez opened this issue Apr 11, 2025 · 2 comments
Open
1 of 2 tasks

Create Database Connection Management #136

CDiezRodriguez opened this issue Apr 11, 2025 · 2 comments
Assignees
Labels
backend enhancement New feature or request python Pull requests that update Python code refine-me! Issues that need to be refined!
Milestone

Comments

@CDiezRodriguez
Copy link
Contributor

Description

Be able to connect to the postgresql

Acceptance Criteria

Additional Information

Example: https://github.com/vnurhaqiqi/fastapi-sqlmodel-postgresql/blob/master/app/db.py
SQLModel: https://sqlmodel.tiangolo.com/tutorial/connect/create-connected-rows/?h=connect#create-rows-for-teams-with-sqlmodel

@CDiezRodriguez CDiezRodriguez added the enhancement New feature or request label Apr 11, 2025
@CDiezRodriguez CDiezRodriguez added backend refine-me! Issues that need to be refined! python Pull requests that update Python code labels Apr 11, 2025
@gomezbc gomezbc added this to the R25.06 milestone Apr 11, 2025
@gomezbc
Copy link
Contributor

gomezbc commented Apr 14, 2025

I did some more research and found that we should follow the SQLModel recommendations for FastAPI by creating a dependency for the database connection. Check out the details here: SQLModel FastAPI Dependency. To connect to the postgresql we need to use a DSN connection string (e.g. postgres://user:pass@localhost:5432/foobar). I will update the helm chart to provide that string

We’ll use this dependency in every request as shown here: Using the Dependency.

To create the class with the connection, we could use pydantic settings management, which injects the configuration from ENV variables, https://docs.pydantic.dev/latest/concepts/pydantic_settings/#usage. Also, it has a type that will help us validate postgresql connection: https://docs.pydantic.dev/latest/api/networks/#pydantic.networks.PostgresDsn

@gomezbc
Copy link
Contributor

gomezbc commented Apr 14, 2025

The connection string will be introduced in #150 as DATABASE_CONNECTION_STRING

@gomezbc gomezbc moved this from Todo to In Progress in Industry Core Hub & Tractus-X SDK Project Apr 15, 2025
@gomezbc gomezbc self-assigned this Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend enhancement New feature or request python Pull requests that update Python code refine-me! Issues that need to be refined!
Projects
Development

No branches or pull requests

2 participants