Created
March 30, 2022 18:48
-
-
Save zehpatricio/0e61f4121eb95e0f8dc162882f84f45e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import sessionmaker | |
SQLALCHEMY_DATABASE_URL = "sqlite:///./sql_alchemy.db" | |
engine = create_engine(SQLALCHEMY_DATABASE_URL) | |
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
Base = declarative_base() | |
def get_db(): | |
Base.metadata.create_all(bind=engine) | |
db = SessionLocal() | |
try: | |
return db | |
finally: | |
db.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment