Add settings helpers
This commit is contained in:
@@ -17,6 +17,7 @@ include_directories(src/include ${DuckDB_SOURCE_DIR}/third_party/httplib)
|
|||||||
set(EXTENSION_SOURCES
|
set(EXTENSION_SOURCES
|
||||||
src/ui_extension.cpp
|
src/ui_extension.cpp
|
||||||
src/http_server.cpp
|
src/http_server.cpp
|
||||||
|
src/settings.cpp
|
||||||
src/state.cpp
|
src/state.cpp
|
||||||
src/utils/encoding.cpp
|
src/utils/encoding.cpp
|
||||||
src/utils/env.cpp
|
src/utils/env.cpp
|
||||||
|
|||||||
29
src/include/settings.hpp
Normal file
29
src/include/settings.hpp
Normal 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
15
src/settings.cpp
Normal 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
|
||||||
Reference in New Issue
Block a user