-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.cpp
64 lines (52 loc) · 1.72 KB
/
database.cpp
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
#include "infra/database.h"
namespace inf::db {
SerializerContext::SerializerContext(const SerializerContext& rhs)
{
_os << rhs._os.str();
}
std::string SerializerContext::str() const
{
return _os.str();
}
void SerializerContext::reset()
{
_os.str("");
}
// std::string SerializerContext::escape(std::string arg)
// {
// return sqlpp::serializer_context_t::escape(arg);
// }
#ifdef INFRA_DB_SQLITE_SUPPORT
sqlpp::sqlite3::connection_config create_sqlite_connection_config(const fs::path& filename, inf::db::AccessMode access, ConnectionDebug debug)
{
sqlpp::sqlite3::connection_config config;
config.path_to_database = filename.string();
if (access == db::AccessMode::ReadOnly) {
config.flags = SQLITE_OPEN_READONLY;
} else if (access == db::AccessMode::ReadWrite) {
config.flags = SQLITE_OPEN_READWRITE;
} else if (access == db::AccessMode::Create) {
config.flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
}
config.debug = debug == ConnectionDebug::Yes;
return config;
}
#endif
#ifdef INFRA_DB_POSTGRES_SUPPORT
std::shared_ptr<sqlpp::postgresql::connection_config> create_postgres_connection_config(const PostgresOptions& options, ConnectionDebug debug)
{
auto config = std::make_shared<sqlpp::postgresql::connection_config>();
config->host = options.host;
config->user = options.user;
config->password = options.pass;
config->dbname = options.databaseName;
config->port = options.port;
config->connect_timeout = options.connectionTimeout;
config->debug = debug == ConnectionDebug::Yes;
#ifdef DEBUG_QUERIES
config->debug = true;
#endif
return config;
}
#endif
}