1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00

🆙 Add Session to Alchemist

This commit is contained in:
Steffo 2020-10-08 14:29:57 +02:00
parent e0c482358c
commit ec156b89b7

View file

@ -1,5 +1,6 @@
from royalnet.typing import * from royalnet.typing import *
import sqlalchemy as sa import sqlalchemy as sa
import sqlalchemy.orm as saorm
__all__ = ( __all__ = (
@ -14,6 +15,7 @@ class Alchemist:
engine_args: Iterable[Any], engine_args: Iterable[Any],
engine_kwargs: Mapping[str, Any]): engine_kwargs: Mapping[str, Any]):
self.engine: sa.engine.Engine = sa.create_engine(*engine_args, **engine_kwargs) self.engine: sa.engine.Engine = sa.create_engine(*engine_args, **engine_kwargs)
self.Session: Union[saorm.sessionmaker, Type[saorm.Session]] = saorm.sessionmaker(bind=self.engine)
def add_metadata(self, metadata: sa.MetaData): def add_metadata(self, metadata: sa.MetaData):
"""Bind a MetaData object to the engine, and create all tables linked with it.""" """Bind a MetaData object to the engine, and create all tables linked with it."""