#!/usr/bin/python3 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("user.id"), 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 card_type = Column(String(1024)) class Deck(Base): __tablename__ = 'deck' id = Column(Integer, primary_key=True, autoincrement=True) owner_id = Column(Integer, ForeignKey("user.id"), 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("user.id"), nullable=False) card_id = Column(Integer, ForeignKey("card.id"), nullable=False) rating_value = Column(Text) #Yes, Maybe, No rating_time = Column(Date) engine = create_engine(CONFIG['DB_CONNECTION']) Base.metadata.create_all(engine) def get_session(): # Engine je samo enkrat treba inicializirat, se mi zdi. # engine = create_engine(CONFIG['DB_CONNECTION']) dbsessionmaker = sessionmaker(bind=engine) return dbsessionmaker()