Add settings helpers

This commit is contained in:
Yves
2025-02-21 11:41:22 +01:00
parent 642988fa94
commit f1bb58e6c7
3 changed files with 45 additions and 0 deletions

29
src/include/settings.hpp Normal file
View File

@@ -0,0 +1,29 @@
#pragma once
#include <duckdb/main/client_context.hpp>
#include <duckdb/common/exception.hpp>
#define UI_LOCAL_PORT_SETTING_NAME "ui_local_port"
#define UI_REMOTE_URL_SETTING_NAME "ui_remote_url"
#define UI_POLLING_INTERVAL_SETTING_NAME "ui_polling_interval"
namespace duckdb {
namespace internal {
template <typename T>
T GetSetting(const ClientContext &context, const char *setting_name) {
Value value;
if (!context.TryGetCurrentSetting(setting_name, value)) {
throw Exception(ExceptionType::SETTINGS,
"Setting \"" + std::string(setting_name) + "\" not found");
}
return value.GetValue<T>();
}
} // namespace internal
std::string GetRemoteUrl(const ClientContext &);
uint16_t GetLocalPort(const ClientContext &);
uint32_t GetPollingInterval(const ClientContext &);
} // namespace duckdb

15
src/settings.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include "settings.hpp"
namespace duckdb {
std::string GetRemoteUrl(const ClientContext &context) {
return internal::GetSetting<std::string>(context, UI_REMOTE_URL_SETTING_NAME);
}
uint16_t GetLocalPort(const ClientContext &context) {
return internal::GetSetting<uint16_t>(context, UI_LOCAL_PORT_SETTING_NAME);
}
uint32_t GetPollingInterval(const ClientContext &context) {
return internal::GetSetting<uint32_t>(context,
UI_POLLING_INTERVAL_SETTING_NAME);
}
} // namespace duckdb