mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
code: hpp,dbal,cpp (2 files)
This commit is contained in:
@@ -496,15 +496,14 @@ class NativePrismaAdapter : public SqlAdapter {
|
||||
public:
|
||||
explicit NativePrismaAdapter(const SqlConnectionConfig& config)
|
||||
: SqlAdapter(config, Dialect::Prisma),
|
||||
requestsClient_(resolveBridgeUrl(config)),
|
||||
bridgeHeaders_(buildBridgeHeaders(resolveBridgeToken(config))) {}
|
||||
requestsClient_(resolveBridgeUrl(config), buildBridgeHeaders(resolveBridgeToken(config))) {}
|
||||
|
||||
std::vector<SqlRow> runQuery(SqlConnection* connection,
|
||||
const std::string& sql,
|
||||
const std::vector<SqlParam>& params) override {
|
||||
(void)connection;
|
||||
const auto payload = buildPayload(sql, params, "query");
|
||||
const auto response = requestsClient_.post("/api/native-prisma", payload.dump(), bridgeHeaders_);
|
||||
const auto response = requestsClient_.post("/api/native-prisma", payload.dump());
|
||||
if (response.statusCode != 200) {
|
||||
throw SqlError{SqlError::Code::Unknown, "Native Prisma bridge request failed"};
|
||||
}
|
||||
@@ -527,7 +526,7 @@ public:
|
||||
const std::vector<SqlParam>& params) override {
|
||||
(void)connection;
|
||||
const auto payload = buildPayload(sql, params, "nonquery");
|
||||
const auto response = requestsClient_.post("/api/native-prisma", payload.dump(), bridgeHeaders_);
|
||||
const auto response = requestsClient_.post("/api/native-prisma", payload.dump());
|
||||
if (response.statusCode != 200) {
|
||||
throw SqlError{SqlError::Code::Unknown, "Native Prisma bridge request failed"};
|
||||
}
|
||||
@@ -568,8 +567,6 @@ private:
|
||||
}
|
||||
|
||||
runtime::RequestsClient requestsClient_;
|
||||
std::unordered_map<std::string, std::string> bridgeHeaders_;
|
||||
|
||||
drogon::Json::Value buildPayload(const std::string& sql,
|
||||
const std::vector<SqlParam>& params,
|
||||
const std::string& type) const {
|
||||
|
||||
@@ -20,8 +20,10 @@ struct RequestsResponse {
|
||||
|
||||
class RequestsClient {
|
||||
public:
|
||||
explicit RequestsClient(std::string baseURL)
|
||||
: baseUrl_(trimTrailingSlash(std::move(baseURL))) {}
|
||||
explicit RequestsClient(std::string baseURL,
|
||||
std::unordered_map<std::string, std::string> defaultHeaders = {})
|
||||
: baseUrl_(trimTrailingSlash(std::move(baseURL))),
|
||||
defaultHeaders_(std::move(defaultHeaders)) {}
|
||||
|
||||
RequestsResponse get(const std::string& path,
|
||||
const std::unordered_map<std::string, std::string>& headers = {},
|
||||
@@ -43,7 +45,7 @@ public:
|
||||
int timeoutMs = 30'000) {
|
||||
const cpr::Url url = cpr::Url{makeUrl(path)};
|
||||
cpr::Header cprHeaders;
|
||||
for (const auto& [key, value] : headers) {
|
||||
for (const auto& [key, value] : mergeHeaders(headers)) {
|
||||
cprHeaders.insert({key, value});
|
||||
}
|
||||
|
||||
@@ -97,6 +99,16 @@ private:
|
||||
}
|
||||
|
||||
std::string baseUrl_;
|
||||
std::unordered_map<std::string, std::string> defaultHeaders_;
|
||||
|
||||
std::unordered_map<std::string, std::string> mergeHeaders(
|
||||
const std::unordered_map<std::string, std::string>& headers) const {
|
||||
auto merged = defaultHeaders_;
|
||||
for (const auto& [key, value] : headers) {
|
||||
merged[key] = value;
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user