示例#1
0
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)
示例#2
0
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))
示例#3
0
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)
示例#4
0
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
示例#5
0
 def __init__(self):
     self.dbhelper = DBHelpers()