Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions sqlite_export_for_ynab/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,35 @@ def insert_budgets(
cur: sqlite3.Cursor, budgets: list[dict[str, Any]], lkos: dict[str, int]
) -> None:
cur.executemany(
"INSERT OR REPLACE INTO budgets (id, name, last_knowledge_of_server) VALUES (?, ?, ?)",
((bid := b["id"], b["name"], lkos[bid]) for b in budgets),
"""
INSERT OR REPLACE INTO budgets (
id
, name
, currency_format_currency_symbol
, currency_format_decimal_digits
, currency_format_decimal_separator
, currency_format_display_symbol
, currency_format_group_separator
, currency_format_iso_code
, currency_format_symbol_first
, last_knowledge_of_server
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
(
bid := b["id"],
b["name"],
b["currency_format"]["currency_symbol"],
b["currency_format"]["decimal_digits"],
b["currency_format"]["decimal_separator"],
b["currency_format"]["display_symbol"],
b["currency_format"]["group_separator"],
b["currency_format"]["iso_code"],
b["currency_format"]["symbol_first"],
lkos[bid],
)
for b in budgets
),
)


Expand Down
7 changes: 7 additions & 0 deletions sqlite_export_for_ynab/ddl/create-relations.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CREATE TABLE IF NOT EXISTS budgets (
id TEXT PRIMARY KEY
, name TEXT
, currency_format_currency_symbol TEXT
, currency_format_decimal_digits INT
, currency_format_decimal_separator TEXT
, currency_format_display_symbol BOOLEAN
, currency_format_group_separator TEXT
, currency_format_iso_code TEXT
, currency_format_symbol_first BOOLEAN
, last_knowledge_of_server INT
)
;
Expand Down
20 changes: 20 additions & 0 deletions testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,30 @@
{
"id": BUDGET_ID_1,
"name": "Budget 1",
"currency_format": {
"currency_symbol": "$",
"decimal_digits": 2,
"decimal_separator": ".",
"display_symbol": True,
"example_format": "123,456.78",
"group_separator": ",",
"iso_code": "USD",
"symbol_first": True,
},
},
{
"id": BUDGET_ID_2,
"name": "Budget 2",
"currency_format": {
"currency_symbol": "$",
"decimal_digits": 2,
"decimal_separator": ".",
"display_symbol": True,
"example_format": "123,456.78",
"group_separator": ",",
"iso_code": "USD",
"symbol_first": True,
},
},
]

Expand Down
14 changes: 14 additions & 0 deletions tests/_main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,25 @@ def test_insert_budgets(cur):
{
"id": BUDGET_ID_1,
"name": BUDGETS[0]["name"],
"currency_format_currency_symbol": "$",
"currency_format_decimal_digits": 2,
"currency_format_decimal_separator": ".",
"currency_format_display_symbol": 1,
"currency_format_group_separator": ",",
"currency_format_iso_code": "USD",
"currency_format_symbol_first": 1,
"last_knowledge_of_server": LKOS[BUDGET_ID_1],
},
{
"id": BUDGET_ID_2,
"name": BUDGETS[1]["name"],
"currency_format_currency_symbol": "$",
"currency_format_decimal_digits": 2,
"currency_format_decimal_separator": ".",
"currency_format_display_symbol": 1,
"currency_format_group_separator": ",",
"currency_format_iso_code": "USD",
"currency_format_symbol_first": 1,
"last_knowledge_of_server": LKOS[BUDGET_ID_2],
},
]
Expand Down