Use the DbTransaction type in the manager
The __conform__ can´t generate a tuple from the class, but it is still worth to use the DB intermediate types for cleaner code. So add tuple() method the the DBTransaction and use it when writing to the DB.
This commit is contained in:
parent
daed9c5814
commit
ea3c75245a
@ -96,7 +96,7 @@ class DatabaseClient:
|
|||||||
|
|
||||||
def insert_transactions(self, transactions: Q.DbTransactions):
|
def insert_transactions(self, transactions: Q.DbTransactions):
|
||||||
logger.info(f"Adding {len(transactions)} into {self.db}")
|
logger.info(f"Adding {len(transactions)} into {self.db}")
|
||||||
self.__executemany(Q.ADD_TRANSACTION, transactions)
|
self.__executemany(Q.ADD_TRANSACTION, [t.tuple() for t in transactions])
|
||||||
|
|
||||||
def update_category(self, transaction: Transaction):
|
def update_category(self, transaction: Transaction):
|
||||||
logger.info(f"Update {transaction} category")
|
logger.info(f"Update {transaction} category")
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import sqlite3
|
|
||||||
|
|
||||||
CREATE_TRANSACTIONS_TABLE = """
|
CREATE_TRANSACTIONS_TABLE = """
|
||||||
CREATE TABLE IF NOT EXISTS "transactions" (
|
CREATE TABLE IF NOT EXISTS "transactions" (
|
||||||
@ -25,8 +24,7 @@ class DbTransaction:
|
|||||||
original: str
|
original: str
|
||||||
comments: str
|
comments: str
|
||||||
|
|
||||||
def __conform__(self, protocol):
|
def tuple(self) -> tuple:
|
||||||
if protocol is sqlite3.PrepareProtocol:
|
|
||||||
return (
|
return (
|
||||||
self.date,
|
self.date,
|
||||||
self.description,
|
self.description,
|
||||||
|
|||||||
@ -13,7 +13,7 @@ def convert(t):
|
|||||||
|
|
||||||
@convert.register
|
@convert.register
|
||||||
def _(t: Transaction) -> DbTransaction:
|
def _(t: Transaction) -> DbTransaction:
|
||||||
return (t.date, t.description, t.bank, t.value, t.category)
|
return DbTransaction(t.date, t.description, t.bank, t.value, t.category, t.original, t.additional_comment)
|
||||||
|
|
||||||
|
|
||||||
@convert.register
|
@convert.register
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user