Add ui_is_started

This commit is contained in:
Yves
2025-02-20 21:57:39 +01:00
parent 0d92a18504
commit 2b93a8d969
3 changed files with 36 additions and 9 deletions

View File

@@ -27,9 +27,10 @@ T GetSetting(const ClientContext &context, const char *setting_name,
} }
namespace internal { namespace internal {
unique_ptr<FunctionData> ResultBind(ClientContext &, TableFunctionBindInput &, unique_ptr<FunctionData> SingleStringResultBind(ClientContext &,
vector<LogicalType> &, TableFunctionBindInput &,
vector<std::string> &); vector<LogicalType> &,
vector<std::string> &);
bool ShouldRun(TableFunctionInput &input); bool ShouldRun(TableFunctionInput &input);
@@ -68,7 +69,8 @@ void TableFunc(ClientContext &context, TableFunctionInput &input,
template <typename Func, Func func> template <typename Func, Func func>
void RegisterTF(DatabaseInstance &instance, const char *name) { void RegisterTF(DatabaseInstance &instance, const char *name) {
TableFunction tf(name, {}, internal::TableFunc<Func, func>, TableFunction tf(name, {}, internal::TableFunc<Func, func>,
internal::ResultBind, RunOnceTableFunctionState::Init); internal::SingleStringResultBind,
RunOnceTableFunctionState::Init);
ExtensionUtil::RegisterFunction(instance, tf); ExtensionUtil::RegisterFunction(instance, tf);
} }

View File

@@ -96,13 +96,32 @@ std::string NotifyConnectedFunction(ClientContext &context,
return "OK"; return "OK";
} }
// - connected notification
std::string NotifyCatalogChangedFunction(ClientContext &context) { std::string NotifyCatalogChangedFunction(ClientContext &context) {
ui::HttpServer::GetInstance(context)->SendCatalogChangedEvent(); ui::HttpServer::GetInstance(context)->SendCatalogChangedEvent();
return "OK"; return "OK";
} }
// - connected notification
unique_ptr<FunctionData> SingleBoolResultBind(ClientContext &,
TableFunctionBindInput &,
vector<LogicalType> &out_types,
vector<std::string> &out_names) {
out_names.emplace_back("result");
out_types.emplace_back(LogicalType::BOOLEAN);
return nullptr;
}
void IsUIStartedTableFunc(ClientContext &context, TableFunctionInput &input,
DataChunk &output) {
if (!internal::ShouldRun(input)) {
return;
}
output.SetCardinality(1);
output.SetValue(0, 0, ui::HttpServer::Started());
}
void InitStorageExtension(duckdb::DatabaseInstance &db) { void InitStorageExtension(duckdb::DatabaseInstance &db) {
auto &config = db.config; auto &config = db.config;
auto ext = duckdb::make_uniq<duckdb::StorageExtension>(); auto ext = duckdb::make_uniq<duckdb::StorageExtension>();
@@ -131,6 +150,11 @@ static void LoadInternal(DatabaseInstance &instance) {
RESISTER_TF("notify_ui_catalog_changed", NotifyCatalogChangedFunction); RESISTER_TF("notify_ui_catalog_changed", NotifyCatalogChangedFunction);
RESISTER_TF_ARGS("notify_ui_connected", {LogicalType::VARCHAR}, RESISTER_TF_ARGS("notify_ui_connected", {LogicalType::VARCHAR},
NotifyConnectedFunction, NotifyConnectedBind); NotifyConnectedFunction, NotifyConnectedBind);
{
TableFunction tf("ui_is_started", {}, IsUIStartedTableFunc,
SingleBoolResultBind, RunOnceTableFunctionState::Init);
ExtensionUtil::RegisterFunction(instance, tf);
}
// If the server is already running we need to update the database instance // If the server is already running we need to update the database instance
// since the previous one was invalidated (eg. in the shell when we '.open' // since the previous one was invalidated (eg. in the shell when we '.open'

View File

@@ -15,9 +15,10 @@ bool ShouldRun(TableFunctionInput &input) {
return true; return true;
} }
unique_ptr<FunctionData> ResultBind(ClientContext &, TableFunctionBindInput &, unique_ptr<FunctionData>
vector<LogicalType> &out_types, SingleStringResultBind(ClientContext &, TableFunctionBindInput &,
vector<std::string> &out_names) { vector<LogicalType> &out_types,
vector<std::string> &out_names) {
out_names.emplace_back("result"); out_names.emplace_back("result");
out_types.emplace_back(LogicalType::VARCHAR); out_types.emplace_back(LogicalType::VARCHAR);
return nullptr; return nullptr;