35 lines
981 B
Python
35 lines
981 B
Python
# ConfigMysql
|
|
|
|
from config import __CONFIG__
|
|
|
|
from sqlalchemy import create_engine, Column, String, Integer
|
|
from sqlalchemy.orm import sessionmaker, declarative_base
|
|
import os
|
|
|
|
# SQLite database file path (in the current directory)
|
|
db_path = os.path.join(os.path.dirname(__file__), 'fastdoi.sqlite3')
|
|
engine = create_engine(f'sqlite:///{db_path}', echo=False)
|
|
Session = sessionmaker(bind=engine)
|
|
session = Session()
|
|
Base = declarative_base()
|
|
|
|
class UploadedPaper(Base):
|
|
__tablename__ = 'uploaded_papers'
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
paperId = Column(String, unique=True, nullable=False)
|
|
|
|
# Create the table if it doesn't exist
|
|
Base.metadata.create_all(engine)
|
|
|
|
def end_sqlalchemy():
|
|
session.close()
|
|
engine.dispose()
|
|
|
|
def is_loaded(paperId):
|
|
return session.query(UploadedPaper).filter_by(paperId=paperId).count() > 0
|
|
|
|
def new_load(paperId):
|
|
paper = UploadedPaper(paperId=paperId)
|
|
session.add(paper)
|
|
session.commit()
|