def update_db_order_completed(env, order_id): """Updates the database when the order is completed""" SQL = f""" UPDATE orders SET completed_at = {env.now} , status = 'Completed' WHERE id = {order_id}; """ with css_cursor() as cur: execute_sql(SQL, cur)
def update_db_order_started(env, order_id): """Updates the database when the order starts being prepared""" SQL = f""" UPDATE orders SET started_at = {env.now} , status = 'In Progress' WHERE id = {order_id}; """ with css_cursor() as cur: execute_sql(SQL, cur)
def update_db_order_received(env, order): """Inserts an order when it is first received""" SQL = f""" INSERT INTO orders (id, status, received_at, customer_name, service, total_price, items) VALUES ( {order['id']} , 'Queued' , {env.now} , '{order['name']}' , '{order['service']}' , {sum([i['price_per_unit'] * i['quantity'] for i in order['items']])} , '{json.dumps({i['name'].replace("'", "''"):i['quantity'] for i in order['items']})}' ); """ with css_cursor() as cur: execute_sql(SQL, cur)
def get_value(): sql = sql_func() with css_cursor() as cur: cur.execute(sql) return cur.fetchone()
def recreate_orders_table(): """Drop and recreate orders table""" with css_cursor() as cur: execute_sql(DOWN_SQL, cur, verbose=True) execute_sql(UP_SQL, cur, verbose=True)