diff options
author | Louie S <louie@example.com> | 2024-02-29 18:01:05 -0500 |
---|---|---|
committer | Louie S <louie@example.com> | 2024-02-29 18:01:05 -0500 |
commit | 4b99428a0e73c9e573624b2784464ce8ae632e33 (patch) | |
tree | 5214b80e74afc4c6844c50852cdad6de4b908912 /src/backend/db_sqlite.h | |
parent | 9852a0ec1b73e1bce0c3f77743b426b29550e01c (diff) |
Rewrite db_sqlite as class
Diffstat (limited to 'src/backend/db_sqlite.h')
-rw-r--r-- | src/backend/db_sqlite.h | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h index fb04c00..bec534b 100644 --- a/src/backend/db_sqlite.h +++ b/src/backend/db_sqlite.h @@ -3,58 +3,62 @@ #include <QString> #include <QStringList> +#include <qsqldatabase.h> #include "../entry.h" #include "../group.h" #include "../rule.h" -// TODO rewrite to be a class (see difference between ::addDatabase and ::database) +class BackendDB : QSqlDatabase { + public: + BackendDB(); + QList<Group *> loadGroups(); + QList<Entry *> loadEntries(); + QList<Rule *> loadRules(); + int insertGroup(const Group &new_group); + int insertEntry(int new_entry); // param datatype TBD + int insertRule(int new_rule); // param datatype TBD + void updateGroup(int group); // param datatype TBD + void updateEntry(int entry); // param datatype TBD + void updateRule(int rule); // param datatype TBD + void removeGroup(int group); // param datatype TBD + void removeEntry(int entry); // param datatype TBD + void removeRule(int rule); // param datatype TBD + void cleanHidden(); -namespace BackendDB { - 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" - ")" - }; + 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" + ")" + }; - void init(); - QList<Group *> loadGroups(); - QList<Entry *> loadEntries(); - QList<Rule *> loadRules(); - int insertGroup(const Group &new_group); // param datatype TBD - int insertEntry(int new_entry); // param datatype TBD - int insertRule(int new_rule); // param datatype TBD - void updateGroup(int group); // param datatype TBD - void updateEntry(int entry); // param datatype TBD - void updateRule(int rule); // param datatype TBD - void removeGroup(int group); // param datatype TBD - void removeEntry(int entry); // param datatype TBD - void removeRule(int rule); // param datatype TBD - void cleanHidden(); + QString getDBPath(); + QSqlDatabase openDB(); }; #endif |