summaryrefslogtreecommitdiff
path: root/src/backend/db_sqlite.h
blob: b23f20866b6f0298dd817e9982ab1ae3856908a3 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef BACKEND_DB_SQLITE_H
#define BACKEND_DB_SQLITE_H

#include <QString>
#include <QStringList>
#include <qsqldatabase.h>

#include "../entry.h"
#include "../group.h"
#include "../rule.h"

class BackendDB : QSqlDatabase {
	public:
		BackendDB();
		QList<Group> loadGroups();
		QList<Entry> loadEntries();
		QList<Entry> loadEntries(int parent_id);
		QList<Rule> loadRules();
		QList<Rule> loadRules(int entry_id);
		int insertGroup(const Group &new_group);
		int insertEntry(const Entry &new_entry);
		int insertRule(const Rule &new_rule);
		void updateGroup(const Group &group);
		void updateEntry(const Entry &entry);
		void updateRule(const Rule &rule);
		int removeGroup(const Group &group);
		int removeEntry(const Entry &entry);
		int removeRule(const Rule &rule);
		void cleanHidden();

	private:
		const QStringList create_table_queries = {
			"CREATE TABLE groups ("
				"id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,"
				"name VARCHAR(255) NOT NULL,"
				"column TINYINT(1) DEFAULT FALSE,"
				"link VARCHAR(255) NOT NULL,"
				"hidden TINYINT(1) DEFAULT FALSE"
				")",
			"CREATE TABLE entries ("
				"id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,"
				"parent_id REFERENCES groups (id),"
				"description VARCHAR(255) NOT NULL,"
				"due_date TEXT DEFAULT NULL,"
				"alt_due_date VARCHAR(255) DEFAULT NULL,"
				"link VARCHAR(255) DEFAULT NULL,"
				"color VARCHAR(255) DEFAULT NULL,"
				"highlight VARCHAR(255) DEFAULT NULL,"
				"done TINYINT(1) DEFAULT FALSE,"
				"hidden TINYINT(1) DEFAULT FALSE"
				")",
			"CREATE TABLE rules ("
				"id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,"
				"entry_id REFERENCES entries (id),"
				"before_after TINYINT(1) DEFAULT TRUE,"
				"date TEXT NOT NULL,"
				"color VARCHAR(255) DEFAULT NULL,"
				"highlight VARCHAR(255) DEFAULT NULL"
				")"
		};

		QString getDBPath();
		QSqlDatabase openDB();
};

#endif