db support
This commit is contained in:
28
db.py
Normal file
28
db.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from sqlalchemy import create_engine, Table, Column, MetaData, Integer, String, Boolean, DateTime, ForeignKey
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker, relationship, mapped_column
|
||||
import os
|
||||
|
||||
# Set up SQLite database
|
||||
if os.getenv("SQLITE_FILE") is not None:
|
||||
sqlite_file = os.getenv("SQLITE_FILE")
|
||||
else:
|
||||
raise Exception("SQLite File not defined!")
|
||||
DATABASE_URI = f'sqlite:///{sqlite_file}'
|
||||
engine = create_engine(DATABASE_URI)
|
||||
Base = declarative_base()
|
||||
|
||||
class DBGroupInstance(Base):
|
||||
__tablename__ = "GroupInstances"
|
||||
object_num = Column(Integer, primary_key=True, autoincrement=True)
|
||||
timestamp = Column(DateTime, nullable=False)
|
||||
instance_id = Column(String, nullable=False)
|
||||
world_name = Column(String, nullable=False)
|
||||
member_count = Column(Integer, nullable=False)
|
||||
|
||||
# Create tables if they don't exist
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
def get_session():
|
||||
Session = sessionmaker(bind=engine)
|
||||
return Session()
|
Reference in New Issue
Block a user