Skip to content

Commit

Permalink
Setup Database:SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
subratamondal1 committed Feb 22, 2024
1 parent 7c5da19 commit a1cebd1
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 1 deletion.
160 changes: 159 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fastapi = "^0.109.2"
uvicorn = "^0.27.0.post1"
jinja2 = "^3.1.3"
requests = "^2.31.0"
sqlalchemy = "^2.0.27"


[build-system]
Expand Down
24 changes: 24 additions & 0 deletions src/app/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Database: Manages connection and sessions for SQLite database."""
import sqlalchemy as _sql

import sqlalchemy.ext.declarative as _declarative
import sqlalchemy.orm as _orm

# database connection string
SQLALCHEMY_DATABASE_URL = "sqlite:///./database.db"

# engine for connecting to the database
ENGINE: _sql.Engine = _sql.create_engine(
url=SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread":False}
)

# session maker for opening database sessions
SESSION_LOCAL = _orm.sessionmaker(
bind=ENGINE, # bind the session maker to the engine
autoflush=False, # disable automatic flushing for performance optimization
autocommit=False # prevent automatic commits for better control
)

# base class for your database models
BASE = _declarative.declarative_base()

0 comments on commit a1cebd1

Please sign in to comment.