diff --git a/src/include/ui_extension.hpp b/src/include/ui_extension.hpp index de39c83..6e26cd2 100644 --- a/src/include/ui_extension.hpp +++ b/src/include/ui_extension.hpp @@ -6,7 +6,12 @@ namespace duckdb { class UiExtension : public Extension { public: +#ifdef DUCKDB_CPP_EXTENSION_ENTRY + void Load(ExtensionLoader &loader) override; +#else void Load(DuckDB &db) override; +#endif + std::string Name() override; std::string Version() const override; }; diff --git a/src/include/utils/helpers.hpp b/src/include/utils/helpers.hpp index 6ecd11d..7e8c649 100644 --- a/src/include/utils/helpers.hpp +++ b/src/include/utils/helpers.hpp @@ -1,7 +1,9 @@ #pragma once #include +#ifndef DUCKDB_CPP_EXTENSION_ENTRY #include +#endif #include namespace duckdb { @@ -64,6 +66,15 @@ void TableFunc(ClientContext &context, TableFunctionInput &input, output.SetValue(0, 0, result); } +#ifdef DUCKDB_CPP_EXTENSION_ENTRY +template +void RegisterTF(ExtensionLoader &loader, const char *name) { + TableFunction tf(name, {}, internal::TableFunc, + internal::SingleStringResultBind, + RunOnceTableFunctionState::Init); + loader.RegisterFunction(tf); +} +#else template void RegisterTF(DatabaseInstance &instance, const char *name) { TableFunction tf(name, {}, internal::TableFunc, @@ -71,10 +82,16 @@ void RegisterTF(DatabaseInstance &instance, const char *name) { RunOnceTableFunctionState::Init); ExtensionUtil::RegisterFunction(instance, tf); } +#endif } // namespace internal +#ifdef DUCKDB_CPP_EXTENSION_ENTRY +#define REGISTER_TF(name, func) \ + internal::RegisterTF(loader, name) +#else #define REGISTER_TF(name, func) \ internal::RegisterTF(instance, name) +#endif } // namespace duckdb diff --git a/src/ui_extension.cpp b/src/ui_extension.cpp index 43b2e83..ded2d07 100644 --- a/src/ui_extension.cpp +++ b/src/ui_extension.cpp @@ -81,7 +81,12 @@ void InitStorageExtension(duckdb::DatabaseInstance &db) { config.storage_extensions[STORAGE_EXTENSION_KEY] = std::move(ext); } +#ifdef DUCKDB_CPP_EXTENSION_ENTRY +static void LoadInternal(ExtensionLoader &loader) { + auto &instance = loader.GetDatabaseInstance(); +#else static void LoadInternal(DatabaseInstance &instance) { +#endif InitStorageExtension(instance); // If the server is already running we need to update the database instance @@ -128,11 +133,20 @@ static void LoadInternal(DatabaseInstance &instance) { TableFunction tf("ui_is_started", {}, IsUIStartedTableFunc, internal::SingleBoolResultBind, RunOnceTableFunctionState::Init); +#ifdef DUCKDB_CPP_EXTENSION_ENTRY + loader.RegisterFunction(tf); +#else ExtensionUtil::RegisterFunction(instance, tf); +#endif } } +#ifdef DUCKDB_CPP_EXTENSION_ENTRY +void UiExtension::Load(ExtensionLoader &loader) { LoadInternal(loader); } +#else void UiExtension::Load(DuckDB &db) { LoadInternal(*db.instance); } +#endif + std::string UiExtension::Name() { return "ui"; } std::string UiExtension::Version() const { return UI_EXTENSION_VERSION; } @@ -141,10 +155,14 @@ std::string UiExtension::Version() const { return UI_EXTENSION_VERSION; } extern "C" { +#ifdef DUCKDB_CPP_EXTENSION_ENTRY +DUCKDB_CPP_EXTENSION_ENTRY(ui, loader) { duckdb::LoadInternal(loader); } +#else DUCKDB_EXTENSION_API void ui_init(duckdb::DatabaseInstance &db) { duckdb::DuckDB db_wrapper(db); db_wrapper.LoadExtension(); } +#endif DUCKDB_EXTENSION_API const char *ui_version() { return duckdb::DuckDB::LibraryVersion();