啥都没用的提交

This commit is contained in:
shufeng2012 committed 2026-08-14 19:39:06 +08:00
1 parent 96d9f96e6d
commit 9bbbc3fdf4
7 files changed
+155 -13

No files matched your search

+5 -13
View File
@@ -8,10 +8,6 @@
namespace shufeng2012 {
template <typename T, typename U> template <typename T, typename U>
class Memdb { class Memdb {
@@ -55,10 +51,10 @@ public:
Memdb() = default; explicit Memdb() = default;
Memdb(int max_time) : MAX_TIME(std::max(0, max_time)) {} explicit Memdb(int max_time) : MAX_TIME(std::max(0, max_time)) {}
Memdb& operator=(const Memdb& to_be_cp_memdb) = default; explicit Memdb& operator=(const Memdb& to_be_cp_memdb) = default;
~Memdb() = default; explicit ~Memdb() = default;
size_t size() const { size_t size() const {
@@ -149,8 +145,4 @@ public:
typename std::list <memdb_column>::iterator it = this -> keys[to_be_sch_k].item; typename std::list <memdb_column>::iterator it = this -> keys[to_be_sch_k].item;
return it -> value; return it -> value;
} }
}; };
}
+72
View File
@@ -0,0 +1,72 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Linker files
*.ilk
# Debugger Files
*.pdb
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
*.so.*
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# Build directories
build/
Build/
build-*/
# CMake generated files
CMakeFiles/
CMakeCache.txt
cmake_install.cmake
#Makefile
install_manifest.txt
compile_commands.json
# Temporary files
*.tmp
*.log
*.bak
*.swp
# vcpkg
vcpkg_installed/
# debug information files
*.dwo
# test output & cache
Testing/
.cache/
# Databases
*.db*
View File
Whitespace-only changes.
View File
Whitespace-only changes.
View File
Whitespace-only changes.
View File
Whitespace-only changes.
+78
View File
@@ -0,0 +1,78 @@
#include <us/RpcServer.hpp>
#include <us/RpcClient.hpp>
#include <boost/json.hpp>
#include <us/memdb.hpp>
#include <string>
#include <iostream>
namespace json = boost::json;
struct ClientConfig {
std::string connected_host = "127.0.0.1";
int connected_port = 8005;
std::string service_name = "db2";
double timeout = 10.0;
bool retry_on_refused = true;
};
struct ServerConfig {
std::string listen_host = "127.0.0.1";
int listen_port = 8011;
int workers = 4;
std::string db_url = "sqlite:///database.db";
};
static std::string get_db_path(const std::string url) {
const std::string prefix = "sqlite:///";
if (url.rfind(prefix, 0) == 0) {
return url.substr(prefix.size());
}
return url;
}
class DBConnection {
private:
ClientConfig __cfg;
public:
explicit DBConnection(const ClientConfig& cfg) :
__cfg(cfg) {}
~DBConnection() = default;
std::string get_from_sql(const std::string& sql_name) {
pmc::net::RpcClient client(__cfg.connected_host, __cfg.connected_port, __cfg.service_name, __cfg.timeout, __cfg.retry_on_refused);
try {
auto data = client.call("execute", {{"action", "select"}, {"table", "memdb"}, {"where", {"sql_name", sql_name}}});
} catch (const std::exception& err) {
std::cerr << "[memdb] Error: 连接失败: " << err.what() << std::endl;
std::exit(1);
}
}
};
class MemdbServer {
private:
ServerConfig __cfg;
public:
explicit MemdbServer(const ServerConfig& cfg) :
__cfg(cfg) {}
void start() {
//TODO 编写
}
};