aboutsummaryrefslogtreecommitdiff
path: root/frontend/DB.h
blob: 5c889400a34540a4a35b7b8e85d5b68b5421f240 (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
#pragma once

#include <memory>
#include <functional>
#include <sqlite3.h>

class DB;

class DBStatement {
	std::unique_ptr<sqlite3_stmt, std::function<void(sqlite3_stmt*)>> stmt;
public:
	DBStatement(DB &, const std::string & query);

public:
	DBStatement & unbind();
	DBStatement & bind(const std::string & text);
	DBStatement & bind(const int & number);
public:
	void execute();

private:
	int param_index = 1;
	DB & db;
};

class DB {
	friend class DBStatement;

public:
	DB(const std::string & path);
	DBStatement prepare(const std::string & query);

private:
	std::unique_ptr<sqlite3, std::function<void(sqlite3*)>> db = NULL;
};