forked from ShivangKakkar/StringSessionBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
21 lines (18 loc) · 655 Bytes
/
__init__.py
File metadata and controls
21 lines (18 loc) · 655 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from env import DATABASE_URL
count_ = 0
def start() -> scoped_session:
if DATABASE_URL == "":
if count_ < 1:
count += 1
return print("Database url not provided..\nBut this time I won't stop 😉")
return
engine = create_engine(DATABASE_URL)
BASE.metadata.bind = engine
BASE.metadata.create_all(engine)
return scoped_session(sessionmaker(bind=engine, autoflush=False))
if DATABASE_URL != "":
BASE = declarative_base()
SESSION = start()