Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def initial_log(self, orders):
- with self.conn.cursor() as cur:
- row_ids = []
- for order in orders:
- cur.execute('INSERT INTO orders (order_num, order_amount)
- VALUES (%s, %s) RETURNING order_id;',
- (order.num, order.amount))
- row_id = cur.fetchone()[0]
- row_ids.append(row_id)
- self.conn.commit()
- return row_ids
- def update_log(self, row_ids, updated_orders):
- with self.conn.cursor() as cur:
- for row_id, order in zip(row_ids, updated_orders):
- status_list = order.messages
- encoded_status = encode_status(status_list)
- cur.execute('UPDATE orders SET (final_order_amount, order_ack,
- order_time, status) =
- (%s, %s, current_timestamp, %s) WHERE order_id = %s',
- (order.final_amount,
- order.ack_num, encoded_status, row_id))
- self.conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement