python-gotosocial-notif/models.py
2024-11-20 20:30:18 +07:00

49 lines
1.1 KiB
Python

# %%
# ZED Python REPL
import os
from sqlalchemy import Column, Date, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
cwd = os.getcwd()
db_dir = f"{cwd}/db"
print(db_dir)
if not os.path.exists(db_dir):
print("Folder db tidak ditemukan, membuat folder db")
os.makedirs(db_dir)
else:
print("Tidak bisa membuat folder db, silakan membuat secara manual folder db")
# Engine
engine = create_engine(f"sqlite:///{db_dir}/gotodon.db")
# Base
Base = declarative_base()
# Models
class Notifikasi(Base):
__tablename__ = "notifikasi"
id = Column(Integer, primary_key=True)
inreplyto = Column(String)
post_id = Column(String, unique=True)
created_at = Column(Date)
handler = Column(String)
display_name = Column(String)
type = Column(String)
status = Column(String)
url = Column(String)
remark = Column(String)
def __repr__(self) -> str:
return f"<{self.id} : {self.handler} >"
# Buat tabel
Base.metadata.create_all(engine)
# Session
Session = sessionmaker(bind=engine)