from ruamel_yaml.util import create_timestamp from custom_decorators import singleton from database import Database from utils.datetime import current_timestamp @singleton class OrderRepository: def __init__(self, config): self.db = Database(config['MYSQL']) def create(self, order_id, from_address, to_address): cur_time = current_timestamp() try: self.db.execute_query( "INSERT INTO orders (order_id, from_address, to_address, create_timestamp, update_timestamp) " "VALUES (%s, %s, %s, %s, %s)", [order_id, from_address, to_address, cur_time, cur_time] ) self.db.commit() except Exception: self.db.rollback() raise def update_status(self, order_id, status): try: self.db.execute_query("UPDATE orders " "SET status = %s, update_timestamp = %s " "WHERE order_id = %s", [status, current_timestamp(), order_id]) self.db.commit() except Exception: self.db.rollback() raise def get_order_info(self, order_id): self.db.execute_query("SELECT quant, from_address, to_address, create_timestamp " "FROM orders " "WHERE order_id = %s", [order_id])