Add ui_is_started
This commit is contained in:
@@ -27,7 +27,8 @@ T GetSetting(const ClientContext &context, const char *setting_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
unique_ptr<FunctionData> ResultBind(ClientContext &, TableFunctionBindInput &,
|
unique_ptr<FunctionData> SingleStringResultBind(ClientContext &,
|
||||||
|
TableFunctionBindInput &,
|
||||||
vector<LogicalType> &,
|
vector<LogicalType> &,
|
||||||
vector<std::string> &);
|
vector<std::string> &);
|
||||||
|
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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'
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ bool ShouldRun(TableFunctionInput &input) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<FunctionData> ResultBind(ClientContext &, TableFunctionBindInput &,
|
unique_ptr<FunctionData>
|
||||||
|
SingleStringResultBind(ClientContext &, TableFunctionBindInput &,
|
||||||
vector<LogicalType> &out_types,
|
vector<LogicalType> &out_types,
|
||||||
vector<std::string> &out_names) {
|
vector<std::string> &out_names) {
|
||||||
out_names.emplace_back("result");
|
out_names.emplace_back("result");
|
||||||
|
|||||||
Reference in New Issue
Block a user