Skip to content

Commit 22721d7

Browse files
committed
Add support for new extension loader
1 parent e06cd34 commit 22721d7

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/include/ui_extension.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ namespace duckdb {
66

77
class UiExtension : public Extension {
88
public:
9+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
10+
void Load(ExtensionLoader &loader) override;
11+
#else
912
void Load(DuckDB &db) override;
13+
#endif
14+
1015
std::string Name() override;
1116
std::string Version() const override;
1217
};

src/include/utils/helpers.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#pragma once
22

33
#include <duckdb.hpp>
4+
#ifndef DUCKDB_CPP_EXTENSION_ENTRY
45
#include <duckdb/main/extension_util.hpp>
6+
#endif
57
#include <type_traits>
68

79
namespace duckdb {
@@ -64,17 +66,32 @@ void TableFunc(ClientContext &context, TableFunctionInput &input,
6466
output.SetValue(0, 0, result);
6567
}
6668

69+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
70+
template <typename Func, Func func>
71+
void RegisterTF(ExtensionLoader &loader, const char *name) {
72+
TableFunction tf(name, {}, internal::TableFunc<Func, func>,
73+
internal::SingleStringResultBind,
74+
RunOnceTableFunctionState::Init);
75+
loader.RegisterFunction(tf);
76+
}
77+
#else
6778
template <typename Func, Func func>
6879
void RegisterTF(DatabaseInstance &instance, const char *name) {
6980
TableFunction tf(name, {}, internal::TableFunc<Func, func>,
7081
internal::SingleStringResultBind,
7182
RunOnceTableFunctionState::Init);
7283
ExtensionUtil::RegisterFunction(instance, tf);
7384
}
85+
#endif
7486

7587
} // namespace internal
7688

89+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
90+
#define REGISTER_TF(name, func) \
91+
internal::RegisterTF<decltype(&func), &func>(loader, name)
92+
#else
7793
#define REGISTER_TF(name, func) \
7894
internal::RegisterTF<decltype(&func), &func>(instance, name)
95+
#endif
7996

8097
} // namespace duckdb

src/ui_extension.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ void InitStorageExtension(duckdb::DatabaseInstance &db) {
8181
config.storage_extensions[STORAGE_EXTENSION_KEY] = std::move(ext);
8282
}
8383

84+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
85+
static void LoadInternal(ExtensionLoader &loader) {
86+
auto &instance = loader.GetDatabaseInstance();
87+
#else
8488
static void LoadInternal(DatabaseInstance &instance) {
89+
#endif
8590
InitStorageExtension(instance);
8691

8792
// If the server is already running we need to update the database instance
@@ -128,11 +133,20 @@ static void LoadInternal(DatabaseInstance &instance) {
128133
TableFunction tf("ui_is_started", {}, IsUIStartedTableFunc,
129134
internal::SingleBoolResultBind,
130135
RunOnceTableFunctionState::Init);
136+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
137+
loader.RegisterFunction(tf);
138+
#else
131139
ExtensionUtil::RegisterFunction(instance, tf);
140+
#endif
132141
}
133142
}
134143

144+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
145+
void UiExtension::Load(ExtensionLoader &loader) { LoadInternal(loader); }
146+
#else
135147
void UiExtension::Load(DuckDB &db) { LoadInternal(*db.instance); }
148+
#endif
149+
136150
std::string UiExtension::Name() { return "ui"; }
137151

138152
std::string UiExtension::Version() const { return UI_EXTENSION_VERSION; }
@@ -141,10 +155,14 @@ std::string UiExtension::Version() const { return UI_EXTENSION_VERSION; }
141155

142156
extern "C" {
143157

158+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
159+
DUCKDB_CPP_EXTENSION_ENTRY(ui, loader) { duckdb::LoadInternal(loader); }
160+
#else
144161
DUCKDB_EXTENSION_API void ui_init(duckdb::DatabaseInstance &db) {
145162
duckdb::DuckDB db_wrapper(db);
146163
db_wrapper.LoadExtension<duckdb::UiExtension>();
147164
}
165+
#endif
148166

149167
DUCKDB_EXTENSION_API const char *ui_version() {
150168
return duckdb::DuckDB::LibraryVersion();

0 commit comments

Comments
 (0)