class UsersDAO(object): def __init__(self): self.dbhelper = DBHelpers() def get_user_by_email(self, email): sql = "SELECT * FROM local.wp_users where user_email = '{}';".format( email) return self.dbhelper.execute_select(sql) def get_number_of_users(self): sql = "SELECT COUNT(*) FROM local.wp_users;" return self.dbhelper.execute_select(sql)
class ProductsDAO(object): def __init__(self): self.dbhelper = DBHelpers() def get_all_products_from_db(self): sql = "select * from wp_posts where post_type = 'product';" response_sql = self.dbhelper.execute_select(sql) return response_sql def get_random_products_from_db(self, qty): sql = "select * from local.wp_posts WHERE post_type = 'product' order by id DESC LIMIT 5000;" response_sql = self.dbhelper.execute_select(sql) return random.sample(response_sql, int(qty))
class OrdersDAO(object): def __init__(self): self.dbhelper = DBHelpers() def get_order_by_id(self, order_id): sql = "SELECT * FROM local.wp_posts WHERE ID = {};".format(order_id) return self.dbhelper.execute_select(sql)
class CouponsDAO(object): def __init__(self): self.dbhelper = DBHelpers() def get_coupon_by_id(self, coupon_id): sql = "SELECT * FROM local.wp_posts WHERE ID = {} AND post_type = 'shop_coupon';".format( coupon_id) return self.dbhelper.execute_select(sql) def get_coupon_metadata_by_id(self, coupon_id): sql = f"SELECT * FROM local.wp_postmeta WHERE post_id = {coupon_id};" response_sql = self.dbhelper.execute_select(sql) logger.debug(f"") logger.debug(f"SQL Result: \n {response_sql}") logger.debug(f"") coupon_meta = dict() for i in response_sql: coupon_meta[i['meta_key']] = i['meta_value'] return coupon_meta
def __init__(self): self.dbhelper = DBHelpers()