forked from CapivaraProjects/repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.py
28 lines (24 loc) · 948 Bytes
/
base.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
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
class Base:
engine = None
Base = declarative_base()
_SessionFactory = None
def __init__(self,
dbuser="",
dbpass="",
dbhost="",
port="",
dbname=""):
self.engine = create_engine(
'postgresql://{}:{}@{}:{}/{}'.format(dbuser,
dbpass,
dbhost,
port,
dbname))
self._SessionFactory = sessionmaker(bind=self.engine)
self.Base = declarative_base()
def session_factory(self):
self.Base.metadata.create_all(self.engine)
return self._SessionFactory()