Skip to content

Commit fd2da87

Browse files
committed
fix: update to new extension interface
1 parent 971898b commit fd2da87

File tree

5 files changed

+69
-17
lines changed

5 files changed

+69
-17
lines changed

CLAUDE.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
DuckDB WebMacro Extension - allows loading DuckDB macros (scalar and table) from URLs, gists, and other remote sources. This is a DuckDB community extension.
8+
9+
## Build Commands
10+
11+
```bash
12+
# Build release version (default)
13+
GEN=ninja make release
14+
15+
# Build debug version
16+
GEN=ninja make debug
17+
18+
```
19+
20+
## Running Tests
21+
22+
Tests use DuckDB's SQLLogicTest format in `test/sql/`:
23+
24+
```bash
25+
# Run tests (release build)
26+
make test
27+
28+
# Run tests (debug build)
29+
make test_debug
30+
```
31+
32+
When running tests use a debug build since it adds more assertions.
33+
34+
All extension functions should be documented inside of DuckDB with CreateScalarFunctionInfo or CreateAggregateFunctionInfo or the appropriate type for the function. This documentation of the function should include examples, parameter types and parameter names. The function should be categorized.
35+
36+
37+
## Architecture
38+
39+
This is a single-file DuckDB extension following the standard extension template pattern:
40+
41+
- `src/webmacro_extension.cpp` - Main extension implementation
42+
- `src/include/webmacro_extension.hpp` - Extension class header
43+
- `extension_config.cmake` - DuckDB extension loader configuration
44+
- `duckdb/` - DuckDB source as git submodule
45+
- `extension-ci-tools/` - DuckDB extension CI tools submodule
46+
47+
The extension registers a single scalar function `load_macro_from_url(VARCHAR) -> VARCHAR` that:
48+
1. Fetches SQL from a URL using httplib
49+
2. Validates the content contains a macro definition
50+
3. Checks for dangerous SQL commands (DELETE, DROP, etc.)
51+
4. Executes the macro creation in DuckDB
52+
5. Returns success message with the macro name
53+
54+
WASM builds use a replacement HTTP library (`wasm_httplib_replacement.hpp`) instead of OpenSSL-based httplib.

duckdb

Submodule duckdb updated 7843 files

src/include/webmacro_extension.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#pragma once
22

33
#include "duckdb.hpp"
4+
#include "duckdb/main/extension/extension_loader.hpp"
45

56
namespace duckdb {
67

78
class WebmacroExtension : public Extension {
89
public:
9-
void Load(DuckDB &db) override;
10+
void Load(ExtensionLoader &loader) override;
1011
std::string Name() override;
11-
std::string Version() const override;
12+
std::string Version() const override;
1213
};
1314

1415
} // namespace duckdb

src/webmacro_extension.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "duckdb/common/exception.hpp"
66
#include "duckdb/common/string_util.hpp"
77
#include "duckdb/function/scalar_function.hpp"
8-
#include "duckdb/main/extension_util.hpp"
8+
#include "duckdb/main/extension/extension_loader.hpp"
99
#include "duckdb/parser/parsed_data/create_macro_info.hpp"
1010
#include <duckdb/parser/parsed_data/create_scalar_function_info.hpp>
1111
#include "duckdb/common/exception/http_exception.hpp"
@@ -217,22 +217,23 @@ static void LoadMacroFromUrlFunction(DataChunk &args, ExpressionState &state, Ve
217217
});
218218
}
219219

220-
static void LoadInternal(DatabaseInstance &instance) {
220+
static void LoadInternal(ExtensionLoader &loader) {
221+
auto &instance = loader.GetDatabaseInstance();
222+
221223
// Create lambda to capture database instance
222224
auto load_macro_func = [&instance](DataChunk &args, ExpressionState &state, Vector &result) {
223225
LoadMacroFromUrlFunction(args, state, result, &instance);
224226
};
225227

226228
// Register function with captured database instance
227-
ExtensionUtil::RegisterFunction(
228-
instance,
229-
ScalarFunction("load_macro_from_url", {LogicalType::VARCHAR},
229+
loader.RegisterFunction(
230+
ScalarFunction("load_macro_from_url", {LogicalType::VARCHAR},
230231
LogicalType::VARCHAR, load_macro_func)
231232
);
232233
}
233234

234-
void WebmacroExtension::Load(DuckDB &db) {
235-
LoadInternal(*db.instance);
235+
void WebmacroExtension::Load(ExtensionLoader &loader) {
236+
LoadInternal(loader);
236237
}
237238

238239
std::string WebmacroExtension::Name() {
@@ -250,13 +251,9 @@ std::string WebmacroExtension::Version() const {
250251
} // namespace duckdb
251252

252253
extern "C" {
253-
DUCKDB_EXTENSION_API void webmacro_init(duckdb::DatabaseInstance &db) {
254-
duckdb::DuckDB db_wrapper(db);
255-
db_wrapper.LoadExtension<duckdb::WebmacroExtension>();
256-
}
257254

258-
DUCKDB_EXTENSION_API const char *webmacro_version() {
259-
return duckdb::DuckDB::LibraryVersion();
255+
DUCKDB_CPP_EXTENSION_ENTRY(webmacro, loader) {
256+
duckdb::LoadInternal(loader);
260257
}
261258
}
262259

0 commit comments

Comments
 (0)