from be.model import postgreSQLORM
from be.model.postgreSQLORM import User, Store_Book, User_Store

class DBConn:
    def __init__(self):
        self.session = postgreSQLORM.session
        return
        # self.conn = store.get_db_conn()

    def user_id_exist(self, user_id):
        row = self.session.query(User).filter(User.user_id==user_id).first()
        # cursor = self.conn.execute("SELECT user_id FROM user WHERE user_id = ?;", (user_id,))
        # row = cursor.fetchone()
        if row is None:
            return False
        else:
            return True

    def book_id_exist(self, store_id, book_id):
        row = self.session.query(Store_Book).filter(Store_Book.book_id==book_id and Store_Book.store_id==store_id).first()
        # cursor = self.conn.execute("SELECT book_id FROM store WHERE store_id = ? AND book_id = ?;", (store_id, book_id))
        # row = cursor.fetchone()
        if row is None:
            return False
        else:
            return True

    def store_id_exist(self, store_id):
        row = self.session.query(User_Store).filter(User_Store.store_id==store_id).first()
        # cursor = self.conn.execute("SELECT store_id FROM user_store WHERE store_id = ?;", (store_id,))
        # row = cursor.fetchone()
        if row is None:
            return False
        else:
            return True
