Replaced SQLAlchemy 1.x-style bulk_insert_mappings(model, data) with SQLAlchemy 2.x-style execute(insert(model), data).

This commit is contained in:
依瑪貓 2023-04-10 19:56:16 +08:00
parent 1e56403b35
commit 40be3fb664
2 changed files with 6 additions and 4 deletions

View File

@ -20,6 +20,7 @@
import csv
import click
import sqlalchemy as sa
from flask.cli import with_appcontext
from accounting import data_dir
@ -45,7 +46,7 @@ def init_base_accounts_command() -> None:
"locale": y,
"title": x[f"l10n-{y}"]}
for x in data for y in locales]
db.session.bulk_insert_mappings(BaseAccount, account_data)
db.session.bulk_insert_mappings(BaseAccountL10n, l10n_data)
db.session.execute(sa.insert(BaseAccount), account_data)
db.session.execute(sa.insert(BaseAccountL10n), l10n_data)
db.session.commit()
click.echo("Base accounts initialized.")

View File

@ -22,6 +22,7 @@ import os
import typing as t
import click
import sqlalchemy as sa
from flask.cli import with_appcontext
from accounting import db, data_dir
@ -77,8 +78,8 @@ def init_currencies_command(username: str) -> None:
"locale": y,
"name": x[f"l10n-{y}"]}
for x in to_add for y in locales]
db.session.bulk_insert_mappings(Currency, currency_data)
db.session.bulk_insert_mappings(CurrencyL10n, l10n_data)
db.session.execute(sa.insert(Currency), currency_data)
db.session.execute(sa.insert(CurrencyL10n), l10n_data)
db.session.commit()
click.echo(F"{len(to_add)} added. Currencies initialized.")