-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.h
54 lines (40 loc) · 1.21 KB
/
Database.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include "models/Account.h"
#include "models/AccountListModel.h"
#include "models/Group.h"
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QSqlQueryModel>
#include <QSqlQuery>
#include <QMap>
class Database: public QObject
{
Q_OBJECT
public:
Database(const QString &dbName, QObject *parent = nullptr);
class AddGroupAccountGuard
{
public:
AddGroupAccountGuard(Database &parent, QSqlDatabase &db);
AddGroupAccountGuard(AddGroupAccountGuard &&) = default;
~AddGroupAccountGuard();
GroupId addGroup(const Group &group);
bool addAccount(const Account &account);
private:
void loadGroupCache();
Database &_parent;
QSqlDatabase &_db;
QSqlQuery *_insertGroupQuery;
QSqlQuery *_insertAccountQuery;
QMap<QString, GroupId> _groupCache;
};
AddGroupAccountGuard makeAddGroupAccountGuard();
QSqlQueryModel *createGroupListModel();
AccountListModel *createAccountListModel(GroupId groupId);
QVector<AccountListModel *> createAccountListModelList(QSqlQueryModel *groupModel);
signals:
void groupAccountUpdated();
private:
void createDatabaseScheme();
QSqlDatabase _db;
};