def get_by_sku(self, sku): p = self.c.execute('SELECT * FROM products WHERE sku=?', (sku, )) try: return ProductModel.fromDB(p.fetchall()[0]) except IndexError: return False
def list(self): p = self.c.execute('SELECT * FROM products') try: return [ProductModel.fromDB(product) for product in p.fetchall()] except Exception as e: raise e
def search(self, **kwargs): query = 'SELECT * FROM products WHERE (' + self.build_query( kwargs) + ')' print(query) results = self.c.execute(query) return [ProductModel.fromDB(r) for r in results.fetchall()]