Changes to db: fixed error in __init__, looking for more precise errors

This commit is contained in:
StNicolay 2022-10-14 17:12:24 +03:00
parent b60579ecd6
commit 85129d8b7a
3 changed files with 11 additions and 8 deletions

View File

@ -1,5 +1,5 @@
import sqlmodel
import mariadb
from sqlalchemy.exc import IntegrityError
from sqlalchemy.future import Engine
from . import models
@ -21,7 +21,7 @@ def add_account(
with sqlmodel.Session(engine) as session:
session.add(account)
session.commit()
except Exception:
except IntegrityError:
return False
else:
return True
@ -34,7 +34,7 @@ def add_master_pass(engine: Engine, user_id: int, salt: bytes, passwd: bytes) ->
with sqlmodel.Session(engine) as session:
session.add(master_pass)
session.commit()
except Exception:
except IntegrityError:
return False
else:
return True

View File

@ -13,4 +13,7 @@ def get_engine(host: str, user: str, passwd: str, db: str) -> Engine:
def prepare(engine: Engine) -> None:
sqlmodel.SQLModel.metadata.create_all(engine, [models.Account, models.MasterPass])
sqlmodel.SQLModel.metadata.create_all(
engine,
# [models.Account, models.MasterPass]
)