Skip to content

Setup Database Connection (Postgres + SQLx) #2

@Akshola00

Description

@Akshola00

Description:
Establish a reliable connection to a PostgreSQL database using the sqlx library. This setup will utilize a connection pool for efficient database interactions and ensure the application can gracefully manage connections.
Requirements:
• Connection Pool Configuration: Implement a connection pool that dynamically manages database connections, optimizing performance and resource utilization.
• Environment Variable: The database connection URL must be securely loaded from environment variables, specifically using DATABASE_URL. This allows for flexibility across different environments, such as development, testing, and production.
Acceptance Criteria:

  1. Environment Variable Loading: Ensure the application correctly retrieves the DATABASE_URL from the environment. Provide a mechanism to handle cases where the variable is absent or incorrectly formatted, including appropriate error messages.
  2. Connection Pool Initialization: The connection pool must be fully initialized during the application startup sequence to ensure availability when handling requests. Document any necessary middleware or configuration steps required for this process.
  3. Health Check Endpoint: Implement an endpoint that verifies the validity of the database connection. The endpoint should return:
    • Status Code 200 (OK) if the connection to the database is active and valid.
    • Relevant Error Codes (e.g., 500 Internal Server Error) if the connection fails, along with an informative message to aid debugging.
  4. Testing: Conduct tests to ensure:
    • The connection pool behaves as expected under load.
    • The health check functionality consistently reports accurate connection statuses.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions