Move from a direct access to DB by the parsers/categorizers to a middle layer, which will bring an easier way to have two input alternatives. This patch starts by instantiating the manager on the cli runnable and using it for the parser function. This patch also moves the queries to a different file, so that introducing new functions on the DB client becomes more manageable and clearer. Finally, the new manager will need converters to move from the code type Transaction to the DB types. This will eventually simplify the code data model by removing more of its method and leaving it a simple dataclass. Issue #14
19 lines
354 B
Python
19 lines
354 B
Python
from functools import singledispatch
|
|
|
|
from pfbudget.core.transactions import Transaction
|
|
|
|
|
|
@singledispatch
|
|
def convert(t):
|
|
pass
|
|
|
|
|
|
@convert.register
|
|
def _(t: Transaction) -> list:
|
|
return (t.date, t.description, t.bank, t.value, t.category)
|
|
|
|
|
|
@convert.register
|
|
def _(transactions: list) -> list[list]:
|
|
return [convert(c) for c in transactions]
|