From f1bb58e6c7db59562c298ec874e36a0a78d7cc0f Mon Sep 17 00:00:00 2001 From: Yves Date: Fri, 21 Feb 2025 11:41:22 +0100 Subject: [PATCH] Add settings helpers --- CMakeLists.txt | 1 + src/include/settings.hpp | 29 +++++++++++++++++++++++++++++ src/settings.cpp | 15 +++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 src/include/settings.hpp create mode 100644 src/settings.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8011a16..047243d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ include_directories(src/include ${DuckDB_SOURCE_DIR}/third_party/httplib) set(EXTENSION_SOURCES src/ui_extension.cpp src/http_server.cpp + src/settings.cpp src/state.cpp src/utils/encoding.cpp src/utils/env.cpp diff --git a/src/include/settings.hpp b/src/include/settings.hpp new file mode 100644 index 0000000..a1a35c6 --- /dev/null +++ b/src/include/settings.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include +#include + +#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 +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(); +} +} // namespace internal + +std::string GetRemoteUrl(const ClientContext &); +uint16_t GetLocalPort(const ClientContext &); +uint32_t GetPollingInterval(const ClientContext &); + +} // namespace duckdb diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..f5af7e5 --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,15 @@ +#include "settings.hpp" + +namespace duckdb { + +std::string GetRemoteUrl(const ClientContext &context) { + return internal::GetSetting(context, UI_REMOTE_URL_SETTING_NAME); +} +uint16_t GetLocalPort(const ClientContext &context) { + return internal::GetSetting(context, UI_LOCAL_PORT_SETTING_NAME); +} +uint32_t GetPollingInterval(const ClientContext &context) { + return internal::GetSetting(context, + UI_POLLING_INTERVAL_SETTING_NAME); +} +} // namespace duckdb