~aleteoryx/muditaos

ref: 78904a6b5d80ab55e1fbf2861ab3a905c96ae94d muditaos/module-db/Tables/EventsTable.hpp -rw-r--r-- 2.0 KiB
78904a6b — Tomas Rogala [EGD-3307] Review changes 5 years ago
                                                                                
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
#pragma once

#include "Table.hpp"
#include "Record.hpp"
#include <Database/Database.hpp>
#include <Common/Common.hpp>
#include <utf8/UTF8.hpp>

struct EventsTableRow : public Record
{
    std::string title;
    std::string description;
    uint32_t date_from = 0;
    uint32_t date_till = 0;
    uint32_t reminder  = 0;
    uint32_t repeat    = 0;
    uint32_t time_zone = 0;
};

enum class EventsTableFields
{
    date_from,
    date_till
};

class EventsTable : public Table<EventsTableRow, EventsTableFields>
{
  public:
    EventsTable(Database *db);
    ~EventsTable() override = default;

    bool create() override final;
    bool add(EventsTableRow entry) override final;
    bool removeById(uint32_t id) override final;
    bool removeByField(EventsTableFields field, const char *str) override final;
    bool update(EventsTableRow entry) override final;
    EventsTableRow getById(uint32_t id) override final;
    std::vector<EventsTableRow> selectByDatePeriod(uint32_t date_from, uint32_t date_till);
    uint32_t count() override final;
    uint32_t countByFieldId(const char *field, uint32_t id) override final;
    std::vector<EventsTableRow> getLimitOffset(uint32_t offset, uint32_t limit) override final;
    std::vector<EventsTableRow> getLimitOffsetByField(uint32_t offset,
                                                      uint32_t limit,
                                                      EventsTableFields field,
                                                      const char *str) override final;

  private:
    const char *createTableQuery = "CREATE TABLE IF NOT EXISTS events("
                                   "_id INTEGER PRIMARY KEY AUTOINCREMENT,"
                                   "title TEXT,"
                                   "description TEXT,"
                                   "date_from INTEGER,"
                                   "date_till INTEGER,"
                                   "reminder INTEGER,"
                                   "repeat INTEGER,"
                                   "time_zone INTEGER);";
};