def add_ledger_action(self, action: LedgerAction) -> int: """Adds a new ledger action to the DB and returns its identifier for success""" cursor = self.db.conn.cursor() query = """ INSERT INTO ledger_actions( timestamp, type, location, amount, asset, rate, rate_asset, link, notes ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);""" cursor.execute(query, action.serialize_for_db()) identifier = cursor.lastrowid self.db.conn.commit() return identifier
def add_ledger_action(self, action: LedgerAction) -> int: """Adds a new ledger action to the DB and returns its identifier for success May raise: - sqlcipher.IntegrityError if there is a conflict at addition in _add_gitcoin_extra_data. If this error is raised connection needs to be rolled back by the caller. """ cursor = self.db.conn.cursor() query = """ INSERT INTO ledger_actions( timestamp, type, location, amount, asset, rate, rate_asset, link, notes ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);""" cursor.execute(query, action.serialize_for_db()) identifier = cursor.lastrowid action.identifier = identifier self.db.conn.commit() return identifier
def edit_ledger_action(self, action: LedgerAction) -> Optional[str]: """Edits a ledger action from the DB by identifier Returns None for success or an error message for error """ error_msg = None cursor = self.db.conn.cursor() query = """ UPDATE ledger_actions SET timestamp=?, type=?, location=?, amount=?, asset=?, rate=?, rate_asset=?, link=?, notes=? WHERE identifier=?""" db_action_tuple = action.serialize_for_db() cursor.execute(query, (*db_action_tuple, action.identifier)) if cursor.rowcount != 1: error_msg = ( f'Tried to edit ledger action with identifier {action.identifier} ' f'but it was not found in the DB') self.db.conn.commit() return error_msg