Skip to content

Add database connection utility#1

Open
rachel11026725 with Copilot wants to merge 3 commits into
masterfrom
copilot/connect-to-database
Open

Add database connection utility#1
rachel11026725 with Copilot wants to merge 3 commits into
masterfrom
copilot/connect-to-database

Conversation

Copilot AI commented Apr 11, 2026

Copy link
Copy Markdown

Adds a minimal Python database connection utility to address the "connect to database" request.

Changes

  • db_connect.pyget_connection(db_url=None) / close_connection(conn) API
    • Defaults to SQLite via DB_PATH env var (no extra deps)
    • Accepts a SQLAlchemy URL for PostgreSQL, MySQL, etc.
    • Proper engine disposal on close; descriptive errors for bad URLs / failed connections
  • requirements.txt — commented-out optional drivers (SQLAlchemy, psycopg2, mysqlclient)
  • README.md — usage docs for both SQLite and SQLAlchemy-backed databases
  • .gitignore — excludes *.db files and Python cache

Usage

from db_connect import get_connection, close_connection

# SQLite (default)
conn = get_connection()

# PostgreSQL (requires: pip install sqlalchemy psycopg2-binary)
conn = get_connection("******localhost:5432/mydb")

close_connection(conn)

DB_PATH env var overrides the default SQLite path (database.db).

ngyikp and others added 2 commits January 20, 2022 12:26
Reviewed By: bigfootjon

Differential Revision: D32665161

fbshipit-source-id: b3854dc4b5cadbcf66a66765ba44b15a107f5a56
@rachel11026725 rachel11026725 changed the base branch from main to master April 11, 2026 00:03
@rachel11026725 rachel11026725 self-requested a review April 11, 2026 00:03
@rachel11026725 rachel11026725 marked this pull request as ready for review April 11, 2026 00:03
Copilot AI changed the title [WIP] Add functionality to connect to database Add database connection utility Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants