Skip to content

Commit 32fcf7e

Browse files
authored
Merge pull request #163 from duckdb/yl/new-ext-loader
Add support for new extension loader
2 parents e06cd34 + ccaf92e commit 32fcf7e

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#ifdef _WIN32
1515
#define OPEN_COMMAND "start"
16+
#undef CreateDirectory // avoid being transformed to `CreateDirectoryA`
1617
#elif __linux__
1718
#define OPEN_COMMAND "xdg-open"
1819
#else
@@ -81,7 +82,12 @@ void InitStorageExtension(duckdb::DatabaseInstance &db) {
8182
config.storage_extensions[STORAGE_EXTENSION_KEY] = std::move(ext);
8283
}
8384

85+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
86+
static void LoadInternal(ExtensionLoader &loader) {
87+
auto &instance = loader.GetDatabaseInstance();
88+
#else
8489
static void LoadInternal(DatabaseInstance &instance) {
90+
#endif
8591
InitStorageExtension(instance);
8692

8793
// If the server is already running we need to update the database instance
@@ -128,11 +134,20 @@ static void LoadInternal(DatabaseInstance &instance) {
128134
TableFunction tf("ui_is_started", {}, IsUIStartedTableFunc,
129135
internal::SingleBoolResultBind,
130136
RunOnceTableFunctionState::Init);
137+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
138+
loader.RegisterFunction(tf);
139+
#else
131140
ExtensionUtil::RegisterFunction(instance, tf);
141+
#endif
132142
}
133143
}
134144

145+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
146+
void UiExtension::Load(ExtensionLoader &loader) { LoadInternal(loader); }
147+
#else
135148
void UiExtension::Load(DuckDB &db) { LoadInternal(*db.instance); }
149+
#endif
150+
136151
std::string UiExtension::Name() { return "ui"; }
137152

138153
std::string UiExtension::Version() const { return UI_EXTENSION_VERSION; }
@@ -141,10 +156,14 @@ std::string UiExtension::Version() const { return UI_EXTENSION_VERSION; }
141156

142157
extern "C" {
143158

159+
#ifdef DUCKDB_CPP_EXTENSION_ENTRY
160+
DUCKDB_CPP_EXTENSION_ENTRY(ui, loader) { duckdb::LoadInternal(loader); }
161+
#else
144162
DUCKDB_EXTENSION_API void ui_init(duckdb::DatabaseInstance &db) {
145163
duckdb::DuckDB db_wrapper(db);
146164
db_wrapper.LoadExtension<duckdb::UiExtension>();
147165
}
166+
#endif
148167

149168
DUCKDB_EXTENSION_API const char *ui_version() {
150169
return duckdb::DuckDB::LibraryVersion();

0 commit comments

Comments
 (0)