-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
43 lines (32 loc) · 978 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base, scoped_session, sessionmaker
from sadco.config import sadco_config
engine = create_engine(
sadco_config.SADCO.DB.URL,
echo=sadco_config.SADCO.DB.ECHO,
isolation_level=sadco_config.SADCO.DB.ISOLATION_LEVEL,
future=True,
)
Session = scoped_session(
sessionmaker(
bind=engine,
autocommit=False,
autoflush=False,
future=True,
)
)
class _Base:
__table_args__ = {"schema": "sadco"}
def save(self):
Session.add(self)
Session.flush()
def delete(self):
Session.delete(self)
Session.flush()
def __repr__(self):
try:
params = ', '.join(f'{attr}={getattr(self, attr)!r}' for attr in getattr(self, '_repr_'))
return f'{self.__class__.__name__}({params})'
except AttributeError:
return object.__repr__(self)
Base = declarative_base(cls=_Base)