app.backbone.database.db
1from contextlib import contextmanager 2from sqlalchemy import create_engine 3from sqlalchemy.ext.declarative import declarative_base 4from sqlalchemy.orm import sessionmaker 5 6DATABASE_URL = "sqlite:///strategyfactory.db" 7 8# engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False}) 9engine = create_engine(DATABASE_URL) 10 11Base = declarative_base() 12Base.metadata.create_all(engine) 13 14SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) 15 16@contextmanager 17def get_db(): 18 db = SessionLocal() 19 try: 20 yield db 21 finally: 22 db.close() 23
DATABASE_URL =
'sqlite:///strategyfactoryapp.backbone.database.db'
engine =
Engine(sqlite:///strategyfactoryapp.backbone.database.db)
class
Base(sqlalchemy.orm.decl_api._DynamicAttributesType, sqlalchemy.inspection.Inspectable[sqlalchemy.orm.mapper.Mapper[typing.Any]]):
The base class of the class hierarchy.
When called, it accepts no arguments and returns a new featureless instance that has no instance attributes and cannot be given any.
Base(**kwargs: Any)
2165def _declarative_constructor(self: Any, **kwargs: Any) -> None: 2166 """A simple constructor that allows initialization from kwargs. 2167 2168 Sets attributes on the constructed instance using the names and 2169 values in ``kwargs``. 2170 2171 Only keys that are present as 2172 attributes of the instance's class are allowed. These could be, 2173 for example, any mapped columns or relationships. 2174 """ 2175 cls_ = type(self) 2176 for k in kwargs: 2177 if not hasattr(cls_, k): 2178 raise TypeError( 2179 "%r is an invalid keyword argument for %s" % (k, cls_.__name__) 2180 ) 2181 setattr(self, k, kwargs[k])
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and
values in kwargs
.
Only keys that are present as attributes of the instance's class are allowed. These could be, for example, any mapped columns or relationships.
SessionLocal =
sessionmaker(class_='Session', autocommit=False, bind=Engine(sqlite:///strategyfactoryapp.backbone.database.db), autoflush=False, expire_on_commit=True)
@contextmanager
def
get_db():