-
Notifications
You must be signed in to change notification settings - Fork 18
/
dbmanager.h
80 lines (68 loc) · 1.91 KB
/
dbmanager.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef DBMANAGER_H
#define DBMANAGER_H
#include <QSqlDatabase>
/**
* \class DbManager
*
* \brief SQL Database Manager class
*
* DbManager sets up the connection with SQL database
* and performs some basics queries. The class requires
* existing SQL database. You can create it with sqlite:
* 1. $ sqlite3 people.db
* 2. sqilte> CREATE TABLE people(ids integer primary key, name text);
* 3. sqlite> .quit
*/
class DbManager
{
public:
/**
* @brief Constructor
*
* Constructor sets up connection with db and opens it
* @param path - absolute path to db file
*/
DbManager(const QString& path);
/**
* @brief Destructor
*
* Close the db connection
*/
~DbManager();
bool isOpen() const;
/**
* @brief Creates a new 'people' table if it doesn't already exist
* @return true - 'people' table created successfully, false - table not created
*/
bool createTable();
/**
* @brief Add person data to db
* @param name - name of person to add
* @return true - person added successfully, false - person not added
*/
bool addPerson(const QString& name);
/**
* @brief Remove person data from db
* @param name - name of person to remove.
* @return true - person removed successfully, false - person not removed
*/
bool removePerson(const QString& name);
/**
* @brief Check if person of name "name" exists in db
* @param name - name of person to check.
* @return true - person exists, false - person does not exist
*/
bool personExists(const QString& name) const;
/**
* @brief Print names of all persons in db
*/
void printAllPersons() const;
/**
* @brief Remove all persons from db
* @return true - all persons removed successfully, false - not removed
*/
bool removeAllPersons();
private:
QSqlDatabase m_db;
};
#endif // DBMANAGER_H