Changed and added comments in the database files
This commit is contained in:
parent
c2280e8bc2
commit
21bd01c3ed
@ -13,7 +13,7 @@ def add_account(
|
||||
enc_login: bytes,
|
||||
enc_pass: bytes,
|
||||
) -> bool:
|
||||
"""Adds account to db. Returns true, if on success"""
|
||||
"""Adds account to the database. Returns true on success, false otherwise"""
|
||||
account = models.Account(
|
||||
user_id=user_id, name=name, salt=salt, enc_login=enc_login, enc_pass=enc_pass
|
||||
)
|
||||
@ -28,7 +28,7 @@ def add_account(
|
||||
|
||||
|
||||
def add_master_pass(engine: Engine, user_id: int, salt: bytes, passwd: bytes) -> bool:
|
||||
"""Adds master password to db. Returns true, if on success"""
|
||||
"""Adds master password the database. Returns true on success, false otherwise"""
|
||||
master_pass = models.MasterPass(user_id=user_id, salt=salt, passwd=passwd)
|
||||
try:
|
||||
with sqlmodel.Session(engine) as session:
|
||||
|
@ -7,6 +7,7 @@ from . import models
|
||||
def change_master_pass(
|
||||
engine: Engine, user_id: int, salt: bytes, passwd: bytes
|
||||
) -> None:
|
||||
"""Changes master password and salt in the database"""
|
||||
statement = (
|
||||
sqlmodel.update(models.MasterPass)
|
||||
.where(models.MasterPass.user_id == user_id)
|
||||
|
@ -5,6 +5,7 @@ from . import models
|
||||
|
||||
|
||||
def purge_accounts(engine: Engine, user_id: int) -> None:
|
||||
"""Deletes all user's accounts"""
|
||||
statement = sqlmodel.delete(models.Account).where(models.Account.user_id == user_id)
|
||||
with sqlmodel.Session(engine) as session:
|
||||
session.exec(statement)
|
||||
@ -12,6 +13,7 @@ def purge_accounts(engine: Engine, user_id: int) -> None:
|
||||
|
||||
|
||||
def delete_master_pass(engine: Engine, user_id: int) -> None:
|
||||
"""Delets master password of the user"""
|
||||
statement = sqlmodel.delete(models.MasterPass).where(
|
||||
models.MasterPass.user_id == user_id
|
||||
)
|
||||
@ -21,6 +23,7 @@ def delete_master_pass(engine: Engine, user_id: int) -> None:
|
||||
|
||||
|
||||
def delete_account(engine: Engine, user_id: int, name: str) -> None:
|
||||
"""Deletes specific user account"""
|
||||
statement = sqlmodel.delete(models.Account).where(
|
||||
models.Account.user_id == user_id, models.Account.name == name
|
||||
)
|
||||
|
@ -5,7 +5,8 @@ from . import models
|
||||
|
||||
|
||||
def get_master_pass(engine: Engine, user_id: int) -> tuple[bytes, bytes] | None:
|
||||
"""Gets master pass. Returns tuple of salt and password"""
|
||||
"""Gets master pass. Returns tuple of salt and password
|
||||
or None if it wasn't found"""
|
||||
statement = sqlmodel.select(models.MasterPass).where(
|
||||
models.MasterPass.user_id == user_id
|
||||
)
|
||||
@ -27,7 +28,8 @@ def get_accounts(engine: Engine, user_id: int) -> list[str]:
|
||||
def get_account_info(
|
||||
engine: Engine, user_id: int, name: str
|
||||
) -> tuple[bytes, bytes, bytes]:
|
||||
"""Gets account info. Returns tuple of salt, login and password"""
|
||||
"""Gets account info. Returns tuple of salt, login and password
|
||||
or None if it wasn't found"""
|
||||
statement = sqlmodel.select(models.Account).where(
|
||||
models.Account.user_id == user_id, models.Account.name == name
|
||||
)
|
||||
|
@ -5,9 +5,11 @@ from . import models
|
||||
|
||||
|
||||
def get_engine(host: str, user: str, passwd: str, db: str) -> Engine:
|
||||
"""Creates an engine for mariadb with pymysql as connector"""
|
||||
engine = sqlmodel.create_engine(f"mariadb+pymysql://{user}:{passwd}@{host}/{db}")
|
||||
return engine
|
||||
|
||||
|
||||
def prepare(engine: Engine) -> None:
|
||||
"""Creates all tables, indexes and constrains in the database"""
|
||||
sqlmodel.SQLModel.metadata.create_all(engine)
|
||||
|
Reference in New Issue
Block a user