You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
647 B
Python
23 lines
647 B
Python
import os
|
|
|
|
from sqlmodel import create_engine, SQLModel, Session
|
|
|
|
|
|
DATABASE_URL = os.environ.get("DATABASE_URL")
|
|
|
|
|
|
# The major differences between SQLModel's create_engine and SQLAlchemy's
|
|
# version is that the SQLModel version adds type annotations (for editor support)
|
|
# and enables the SQLAlchemy "2.0" style of engines and connections.
|
|
engine = create_engine(DATABASE_URL, echo=True) # Will want a "debug mode where it doesn't echo for prod
|
|
|
|
|
|
def init_db():
|
|
SQLModel.metadata.create_all(engine)
|
|
|
|
|
|
def get_session():
|
|
"""A coroutine function for getting a database session."""
|
|
with Session(engine) as session:
|
|
yield session
|