Filled delete.py and created change.py

This commit is contained in:
StNicolay 2022-10-14 17:48:32 +03:00
parent 85129d8b7a
commit 7fe7b23a63
3 changed files with 36 additions and 2 deletions

View File

@ -1,3 +1,3 @@
from . import add, delete, get, models, prepare from . import add, delete, get, models, prepare, change
__all__ = ["add", "delete", "get", "models", "prepare"] __all__ = ["add", "delete", "get", "models", "prepare", "change"]

16
src/database/change.py Normal file
View File

@ -0,0 +1,16 @@
import sqlmodel
from sqlalchemy.future import Engine
from . import models
def change_master_pass(
engine: Engine, user_id: int, salt: bytes, passwd: bytes
) -> None:
statement = sqlmodel.update(
models.MasterPass,
models.MasterPass.user_id == user_id,
sqlmodel.values(salt=salt, passwd=passwd),
)
with sqlmodel.Session(engine) as session:
session.exec(statement)

View File

@ -0,0 +1,18 @@
import sqlmodel
from sqlalchemy.future import Engine
from . import models
def purge_accounts(engine: Engine, user_id: int) -> None:
statement = sqlmodel.delete(models.Account).where(models.Account.user_id == user_id)
with sqlmodel.Session(engine) as session:
session.exec(statement)
def delete_master_pass(engine: Engine, user_id: int) -> None:
statement = sqlmodel.delete(models.MasterPass).where(
models.MasterPass.user_id == user_id
)
with sqlmodel.Session(engine) as session:
session.exec(statement)