Added ordering by name for accounts

This commit is contained in:
StNicolay 2022-12-06 14:16:03 +03:00
parent b0599c1484
commit d82d152fef

View File

@ -24,9 +24,13 @@ def get_master_pass(
def get_accounts(engine: Engine, user_id: int) -> list[str]: def get_accounts(engine: Engine, user_id: int) -> list[str]:
"""Gets list of account names""" """Gets list of account names"""
statement = sqlmodel.select(models.Account).where( statement = (
sqlmodel.select(models.Account)
.where(
models.Account.user_id == user_id, models.Account.user_id == user_id,
) )
.order_by(models.Account.name)
)
with sqlmodel.Session(engine) as session: with sqlmodel.Session(engine) as session:
result = session.exec(statement) result = session.exec(statement)
return [account.name for account in result] return [account.name for account in result]
@ -37,9 +41,13 @@ def get_all_accounts(
) -> Iterator[tuple[str, bytes, bytes, bytes]]: ) -> Iterator[tuple[str, bytes, bytes, bytes]]:
"""Returns an iterator of tuples, where values represent account's """Returns an iterator of tuples, where values represent account's
name, salt, encrypted login and encrypted password""" name, salt, encrypted login and encrypted password"""
statement = sqlmodel.select(models.Account).where( statement = (
sqlmodel.select(models.Account)
.where(
models.Account.user_id == user_id, models.Account.user_id == user_id,
) )
.order_by(models.Account.name)
)
with sqlmodel.Session(engine) as session: with sqlmodel.Session(engine) as session:
result = session.exec(statement) result = session.exec(statement)
yield from ( yield from (