You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.0 KiB

from sqlalchemy import Column, Integer, Float, String, Text, Date, ForeignKey, BOOLEAN
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config import CONFIG
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True, autoincrement=True)
username = Column(String(64))
password = Column(String(64))
email = Column(Text)
settings = Column(Text) #neki json...
class Card(Base):
__tablename__ = 'card'
id = Column(Integer, primary_key=True, autoincrement=True)
title = Column(String(1024))
owner_id = Column(Integer, ForeignKey(""), nullable=False)
interest_rate = Column(Float)
item_location = Column(String(1024))
last_review = Column(Text)
share_id = Column(Text) #explain: 0 means not shared, otherwise increment from db and generate new cards for all relevant(tbd) users
class Deck(Base):
__tablename__ = 'deck'
id = Column(Integer, primary_key=True, autoincrement=True)
owner_id = Column(Integer, ForeignKey(""), nullable=False)
cards_by_id = Column(Text)
number_of_cards = Column(Integer)
current_card = Column(Integer)
completed = Column(BOOLEAN)
class Rating(Base):
__tablename__ = 'rating'
id = Column(Integer, primary_key=True, autoincrement=True)
user_id = Column(Integer, ForeignKey(""), nullable=False)
card_id = Column(Integer, ForeignKey(""), nullable=False)
rating_value = Column(Text) #Yes, Maybe, No
rating_time = Column(Date)
engine = create_engine(CONFIG['DB_CONNECTION'])
def get_session():
# Engine je samo enkrat treba inicializirat, se mi zdi.
# engine = create_engine(CONFIG['DB_CONNECTION'])
dbsessionmaker = sessionmaker(bind=engine)
return dbsessionmaker()