SecretService 0.13.2d47dfe
SecretService is base back end library for your c++ Qt projects.
secretdatabase.cpp
Go to the documentation of this file.
1//#
2//# Copyright (C) 2024-2024 QuasarApp.
3//# Distributed under the GPLv3 software license, see the accompanying
4//# Everyone is permitted to copy and distribute verbatim copies
5//# of this license document, but changing it is not allowed.
6//#
7
8#include "secretdatabase.h"
9#include <QCoreApplication>
10#include "record.h"
11#include <QCryptographicHash>
12#include <dbobjectsrequest.h>
13#include <sqldb.h>
14
15namespace DBSecret {
16
18
19 addDBPatch({
20 0,
21 1,
22 [](const QH::iObjectProvider* database) -> bool {
23 return database->doSql(":/src/sql/SecretDB_1.sql");
24 }
25 });
26
27}
28
30 return {
31 {QH_DB_DRIVER, "QSQLITE"},
32 {QH_DB_FILE_PATH, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/QASecret.sqlite" },
33 {QH_DB_BACKUP_PATH, QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/QASecretBackUps"}
34 };
35}
36
37QSharedPointer<iRecord>
38SecretDataBase::getRecordByAlias(const QString &alias, bool ifNotExistsCreate) {
39 return getById<Record>(alias, &Record::setAlias, ifNotExistsCreate);
40}
41
42QSharedPointer<iRecord>
43SecretDataBase::getRecordByHash(const QByteArray &hash, bool ifNotExistsCreate) {
44 return getById<Record>(hash, &Record::setHash, ifNotExistsCreate);
45}
46
47bool SecretDataBase::saveRecord(const QSharedPointer<iRecord> &record) {
48 return db()->replaceObject(record.staticCast<Record>(), true);
49}
50
51bool SecretDataBase::removeRecordByAlias(const QString &alias) {
52 return deleteById<Record>(alias, &Record::setAlias);
53}
54
55bool SecretDataBase::removeRecordByKey(const QByteArray &hash) {
56 return deleteById<Record>(hash, &Record::setHash);
57}
58
59}
The Record class.
Definition record.h:24
void setAlias(const QString &alias) override
setAlias This method sets new alias for record.
Definition record.cpp:61
void setHash(const QByteArray &source) override
setHash This method sets new hash of record.
Definition record.cpp:69
bool removeRecordByKey(const QByteArray &hash) override
removeRecordByKey This method will remove record by hash key.
bool removeRecordByAlias(const QString &alias) override
removeRecordByAlias This method will remove record by alias.
bool saveRecord(const QSharedPointer< iRecord > &record) override
saveRecord This method save a record object into database.
QSharedPointer< iRecord > getRecordByAlias(const QString &alias, bool ifNotExistsCreate) override
Get a user by their ID.
QVariantMap defaultDbParams() const override
QSharedPointer< iRecord > getRecordByHash(const QByteArray &hash, bool ifNotExistsCreate) override
getRecordByHash Get record by hash.
QSharedPointer< IDataBase > database()
Definition SecretDB.cpp:21