mirror of
https://github.com/rjNemo/pass-gen
synced 2026-06-06 02:26:42 +00:00
30 lines
856 B
Python
30 lines
856 B
Python
import app.data.sqlite as sqlite
|
|
from app.data.type import DBConnector
|
|
from app.models.password import Password
|
|
|
|
|
|
class PasswordRepository:
|
|
def __init__(self, db: DBConnector) -> None:
|
|
self.db = db
|
|
|
|
def save(self, service: str, password: str) -> None:
|
|
try:
|
|
self.db.execute(
|
|
"INSERT INTO passwords VALUES (null, :service, :password)",
|
|
{"service": service, "password": password},
|
|
)
|
|
|
|
self.db.commit()
|
|
except Exception as e:
|
|
print(e)
|
|
|
|
def list_all(self) -> list[Password]:
|
|
return [
|
|
Password(id=row[0], service=row[1], password=row[2])
|
|
for row in self.db.execute("SELECT * FROM " "passwords").fetchall()
|
|
]
|
|
|
|
|
|
def get_instance() -> PasswordRepository:
|
|
db = sqlite.DB()
|
|
return PasswordRepository(db)
|