NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
db_config.hpp
浏览该文件的文档.
1#ifndef NEFORCE_DATABASE_DB_CONFIG_HPP__
2#define NEFORCE_DATABASE_DB_CONFIG_HPP__
3
12
14NEFORCE_BEGIN_NAMESPACE__
15
21
26struct database_typecast_exception final : database_exception {
27 explicit database_typecast_exception(const char* info = "Database Type Mismatch.", const char* type = static_type,
28 const int code = 0) noexcept :
29 database_exception(info, type, code) {}
30
31 explicit database_typecast_exception(const exception& e) :
32 database_exception(e) {}
33
34 ~database_typecast_exception() override = default;
35 static constexpr auto static_type = "database_typecast_exception";
36};
37
42struct database_stmt_exception final : database_exception {
43 explicit database_stmt_exception(const char* info = "Database Statement Operations Error.",
44 const char* type = static_type, const int code = 0) noexcept :
45 database_exception(info, type, code) {}
46
47 explicit database_stmt_exception(const exception& e) :
48 database_exception(e) {}
49
50 ~database_stmt_exception() override = default;
51 static constexpr auto static_type = "database_prepared_stmt_exception";
52};
53 // Exceptions
55
61
69enum class db_type : uint8_t {
70#ifdef NEFORCE_SUPPORT_MYSQL
71 MYSQL = 1,
72#endif
73#ifdef NEFORCE_SUPPORT_SQLITE3
75#endif
76#ifdef NEFORCE_SUPPORT_HIREDIS
78#endif
79#ifdef NEFORCE_SUPPORT_POSTGRESQL
81#endif
82};
83
91struct NEFORCE_API db_config {
92 string username{};
93 string password{};
94 string database{};
95 string host = "127.0.0.1";
96 string charset{};
98
99#ifdef NEFORCE_SUPPORT_POSTGRESQL
110 static db_config for_postgresql(const string& db = "postgres");
111#endif
112
113#ifdef NEFORCE_SUPPORT_MYSQL
124 static db_config for_mysql(const string& db);
125#endif
126
127#ifdef NEFORCE_SUPPORT_SQLITE3
136 static db_config for_sqlite(const string& file);
137#endif
138
139#ifdef NEFORCE_SUPPORT_HIREDIS
149 static db_config for_redis(const string& db);
150#endif
151};
152 // Database
154
155NEFORCE_END_NAMESPACE__
156#endif // NEFORCE_DATABASE_DB_CONFIG_HPP__
文件操作类
unsigned char uint8_t
8位无符号整数类型
db_type
数据库类型枚举
@ MYSQL
MySQL数据库
@ POSTGRESQL
PostgreSQL数据库
@ REDIS
Redis键值存储
@ SQLITE3
SQLite3数据库
网络端口定义和转换工具
数据库连接配置结构
string password
数据库密码
static db_config for_postgresql(const string &db="postgres")
创建PostgreSQL数据库配置
static db_config for_sqlite(const string &file)
创建SQLite3数据库配置
string username
数据库用户名
string charset
数据库字符集
ports port
数据库端口号
string host
数据库主机地址
static db_config for_mysql(const string &db)
创建MySQL数据库配置
static db_config for_redis(const string &db)
创建Redis数据库配置
string database
数据库名
exception(const char *info=static_type, const char *type=static_type, const int code=0)
构造函数
NEFORCE_NODISCARD int code() const noexcept
获取异常码
NEFORCE_NODISCARD const char * type() const noexcept
获取异常类型
网络端口封装类