Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/database/orm.py

25 lines
535 B
Python
Raw Normal View History

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
2021-08-07 07:56:48 +00:00
from config import Config
2022-06-13 04:49:22 +00:00
from database.orm_base import Base
2021-07-28 18:51:24 +00:00
DB_LINK = Config('db_path')
2021-10-20 14:04:30 +00:00
2021-08-24 16:49:19 +00:00
class DBSession:
def __init__(self):
self.engine = engine = create_engine(DB_LINK)
self.Session = sessionmaker()
self.Session.configure(bind=self.engine)
2021-08-24 16:49:19 +00:00
@property
def session(self):
return self.Session()
2022-06-13 04:49:22 +00:00
def create(self):
Base.metadata.create_all(bind=self.engine, checkfirst=True)
Session = DBSession()