This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
PassManager/src/db/add.py

32 lines
841 B
Python
Raw Normal View History

2022-10-14 12:38:03 +00:00
import sqlmodel
from sqlalchemy.exc import IntegrityError
2022-10-14 12:38:03 +00:00
from sqlalchemy.future import Engine
from . import models
2022-10-05 12:04:39 +00:00
2022-09-29 13:02:11 +00:00
def add_account(engine: Engine, account: models.Account) -> bool:
2022-11-30 16:41:57 +00:00
"""Adds account to the database. Returns true on success,
false otherwise"""
2022-10-05 11:52:23 +00:00
try:
2022-10-14 12:38:03 +00:00
with sqlmodel.Session(engine) as session:
session.add(account)
session.commit()
except IntegrityError:
2022-10-05 11:52:23 +00:00
return False
else:
return True
2022-09-29 13:02:11 +00:00
def add_master_pass(engine: Engine, master_pass: models.MasterPass) -> bool:
2022-11-30 16:41:57 +00:00
"""Adds master password the database. Returns true on success,
false otherwise"""
2022-10-05 11:52:23 +00:00
try:
2022-10-14 12:38:03 +00:00
with sqlmodel.Session(engine) as session:
session.add(master_pass)
session.commit()
except IntegrityError:
2022-10-05 11:52:23 +00:00
return False
else:
return True