def add_order(receiver): """ Add new order Parameters ---------- receiver : str Returns ------- order_list : List[OrderEntity] """ sql = 'INSERT INTO sprzedaz.zamowienia (odbiorca) VALUES (%s);' val = (receiver,) DBconnector.execute_query_insert(sql, val)
def select_all(): """ Select all from products table (produkty) Returns ------- order_list : List[ProductDAO] """ sql = 'SELECT * FROM sprzedaz.produkty' rows = DBconnector.fetch_query(sql) return _wrap_in_order_list(rows)
def select_last(): """ Select all from Orders table (zamowienia) Returns ------- order_list : List[OrderEntity] """ sql = 'SELECT * FROM sprzedaz.zamowienia ORDER by zamowienie_id DESC LIMIT 1;' rows = DBconnector.fetch_query(sql) return _wrap_in_order_list(rows)
def select_all(): """ Select all from (producy_zamowien) Returns ------- order_list : List[OrderProductsEntity] """ sql = 'SELECT * FROM sprzedaz.produkty_zamowien pz ' \ 'JOIN sprzedaz.produkty p on pz.produkt_id = p.produkt_id ' \ 'JOIN sprzedaz.zamowienia z on pz.zamowienie_id = z.zamowienie_id' rows = DBconnector.fetch_query(sql) return _wrap_in_orders_products_list(rows)
def select_products_order_qunatity(): """ Select quantity of each product from orders Returns ------- order_list : List[ProductDAO] """ sql = "SELECT DISTINCT p.produkt_id, p.nazwa, " \ "(SELECT SUM(pz.ilosc) FROM produkty_zamowien pz WHERE pz.produkt_id = p.produkt_id) AS `stan_zamowienia`" \ ", cena_jednostkowa " \ "FROM sprzedaz.produkty p;" rows = DBconnector.fetch_query(sql) return _wrap_in_order_list(rows)
def select_last(count): """ Select last element from table Returns ------- order_list : List[OrderProductsEntity] """ sql = 'SELECT * FROM sprzedaz.produkty_zamowien pz ' \ 'JOIN sprzedaz.produkty p on pz.produkt_id = p.produkt_id ' \ 'JOIN sprzedaz.zamowienia z on pz.zamowienie_id = z.zamowienie_id '\ 'ORDER by pz.produkty_zamowien_id DESC LIMIT %s;' val = (count, ) rows = DBconnector.fetch_query_parameters(sql, val) return _wrap_in_orders_products_list(rows)
def select_by_id(order_id): """ Select order by ID Parameters ---------- order_id : str Returns ------- order_list : List[OrderEntity] """ sql = "SELECT * FROM sprzedaz.zamowienia WHERE zamowienie_id = %s;" val = (order_id,) rows = DBconnector.fetch_query_parameters(sql, val) return _wrap_in_order_list(rows)
def insert(product_id, product_quantity, order_id): """ Add order if product is available Parameters ---------- product_id : str product_quantity : str order_id : str Returns ------- order_list : List[OrderEntity] """ sql = 'add_order_if_can' val = [product_id, product_quantity, order_id] rows = DBconnector.call_procedure(sql, val) return _wrap_in_order_list(rows)