Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
 def get_value():
     sql = sql_func()
     with css_cursor() as cur:
         cur.execute(sql)
         return cur.fetchone()
Exemple #5
0
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)