You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* explicit duckdb 1.29.0; self-host core extensions; document
* configure which extensions are self-hosted
(not quite there yet: still need to do hashing, per-extension configuration of the LOAD command, and per page configuration)
* hash extensions
* better docs
* cleaner duckdb manifest — now works in scripts and embeds
* restructure code, extensible manifest
* test, documentation
* much nicer config
* document config
* add support for mvp, clean config & documentation
* parametrized the initial LOAD in DuckDBClient
* tests
* bake-in the extensions manifest
* fix test
* don't activate spatial on the documentation
* refactor: hash individual extensions, include the list of platforms in the config (not configurable yet)
* don't copy extensions twice
* Update src/duckdb.ts
Co-authored-by: Mike Bostock <mbostock@gmail.com>
* remove DuckDBClientReport utility
* renames
* p for platform
* centralize DUCKDBWASMVERSION and DUCKDBVERSION
* clearer
* better config; manifest.extensions now lists individual extensions once only, with one reference per platform
* validate extension names; centralize DUCKDBBUNDLES
* fix tests
* copy edit
* support loading non-self-hosted extensions
* test duckdb config normalization & defaults
* documentation
* typography
* doc
* use view for <50MB
* docs, shorthand, etc.
* annotate fixes
* disable telemetry on annotate tests, too
* tidier duckdb manifest
* remove todo
* more robust duckdb: scheme
---------
Co-authored-by: Mike Bostock <mbostock@gmail.com>
Copy file name to clipboardExpand all lines: docs/config.md
+39Lines changed: 39 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -301,6 +301,45 @@ export default {
301
301
};
302
302
```
303
303
304
+
## duckdb <ahref="https://github.com/observablehq/framework/pull/1734"class="observablehq-version-badge"data-version="prerelease"title="Added in #1734"></a>
305
+
306
+
The **duckdb** option configures [self-hosting](./lib/duckdb#self-hosting-of-extensions) and loading of [DuckDB extensions](./lib/duckdb#extensions) for use in [SQL code blocks](./sql) and the `sql` and `DuckDBClient` built-ins. For example, a geospatial data app might enable the [`spatial`](https://duckdb.org/docs/extensions/spatial/overview.html) and [`h3`](https://duckdb.org/community_extensions/extensions/h3.html) extensions like so:
307
+
308
+
```js run=false
309
+
exportdefault {
310
+
duckdb: {
311
+
extensions: ["spatial", "h3"]
312
+
}
313
+
};
314
+
```
315
+
316
+
The **extensions** option can either be an array of extension names, or an object whose keys are extension names and whose values are configuration options for the given extension, including its **source** repository (defaulting to the keyword _core_ for core extensions, and otherwise _community_; can also be a custom repository URL), whether to **load** it immediately (defaulting to true, except for known extensions that support autoloading), and whether to **install** it (_i.e._ to self-host, defaulting to true). As additional shorthand, you can specify `[name]: true` to install and load the named extension from the default (_core_ or _community_) source repository, or `[name]: string` to install and load the named extension from the given source repository.
The `json` and `parquet` are configured (and therefore self-hosted) by default. To expressly disable self-hosting of extension, you can set its **install** property to false, or equivalently pass null as the extension configuration object.
340
+
341
+
For more, see [DuckDB extensions](./lib/duckdb#extensions).
342
+
304
343
## markdownIt <ahref="https://github.com/observablehq/framework/releases/tag/v1.1.0"class="observablehq-version-badge"data-version="^1.1.0"title="Added in v1.1.0"></a>
305
344
306
345
A hook for registering additional [markdown-it](https://github.com/markdown-it/markdown-it) plugins. For example, to use [markdown-it-footnote](https://github.com/markdown-it/markdown-it-footnote), first install the plugin with either `npm add markdown-it-footnote` or `yarn add markdown-it-footnote`, then register it like so:
For externally-hosted data, you can create an empty `DuckDBClient` and load a table from a SQL query, say using [`read_parquet`](https://duckdb.org/docs/guides/import/parquet_import) or [`read_csv`](https://duckdb.org/docs/guides/import/csv_import). DuckDB offers many affordances to make this easier (in many cases it detects the file format and uses the correct loader automatically).
68
+
For externally-hosted data, you can create an empty `DuckDBClient` and load a table from a SQL query, say using [`read_parquet`](https://duckdb.org/docs/guides/import/parquet_import) or [`read_csv`](https://duckdb.org/docs/guides/import/csv_import). DuckDB offers many affordances to make this easier. (In many cases it detects the file format and uses the correct loader automatically.)
## Extensions <ahref="https://github.com/observablehq/framework/pull/1734"class="observablehq-version-badge"data-version="prerelease"title="Added in #1734"></a>
110
+
111
+
[DuckDB extensions](https://duckdb.org/docs/extensions/overview.html) extend DuckDB’s functionality, adding support for additional file formats, new types, and domain-specific functions. For example, the [`json` extension](https://duckdb.org/docs/data/json/overview.html) provides a `read_json` method for reading JSON files:
112
+
113
+
```sql echo
114
+
SELECT bbox FROM read_json('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson');
115
+
```
116
+
117
+
To read a local file (or data loader), use `FileAttachment` and interpolation `${…}`:
118
+
119
+
```sql echo
120
+
SELECT bbox FROM read_json(${FileAttachment("../quakes.json").href});
121
+
```
122
+
123
+
For convenience, Framework configures the `json` and `parquet` extensions by default. Some other [core extensions](https://duckdb.org/docs/extensions/core_extensions.html) also autoload, meaning that you don’t need to explicitly enable them; however, Framework will only [self-host extensions](#self-hosting-of-extensions) if you explicitly configure them, and therefore we recommend that you always use the [**duckdb** config option](../config#duckdb) to configure DuckDB extensions. Any configured extensions will be automatically [installed and loaded](https://duckdb.org/docs/extensions/overview#explicit-install-and-load), making them available in SQL code blocks as well as the `sql` and `DuckDBClient` built-ins.
124
+
125
+
For example, to configure the [`spatial` extension](https://duckdb.org/docs/extensions/spatial/overview.html):
126
+
127
+
```js run=false
128
+
exportdefault {
129
+
duckdb: {
130
+
extensions: ["spatial"]
131
+
}
132
+
};
133
+
```
134
+
135
+
You can then use the `ST_Area` function to compute the area of a polygon:
To tell which extensions have been loaded, you can run the following query:
142
+
143
+
```sql echo
144
+
FROM duckdb_extensions() WHERE loaded;
145
+
```
146
+
147
+
<divclass="warning">
148
+
149
+
If the `duckdb_extensions()` function runs before DuckDB autoloads a core extension (such as `json`), it might not be included in the returned set.
150
+
151
+
</div>
152
+
153
+
### Self-hosting of extensions
154
+
155
+
As with [npm imports](../imports#self-hosting-of-npm-imports), configured DuckDB extensions are self-hosted, improving performance, stability, & security, and allowing you to develop offline. Extensions are downloaded to the DuckDB cache folder, which lives in <code>.observablehq/<wbr>cache/<wbr>\_duckdb</code> within the source root (typically `src`). You can clear the cache and restart the preview server to re-fetch the latest versions of any DuckDB extensions. If you use an [autoloading core extension](https://duckdb.org/docs/extensions/core_extensions.html#list-of-core-extensions) that is not configured, DuckDB-Wasm [will load it](https://duckdb.org/docs/api/wasm/extensions.html#fetching-duckdb-wasm-extensions) from the default extension repository, `extensions.duckdb.org`, at runtime.
156
+
157
+
## Configuring
158
+
159
+
The second argument to `DuckDBClient.of` and `DuckDBClient.sql` is a [`DuckDBConfig`](https://shell.duckdb.org/docs/interfaces/index.DuckDBConfig.html) object which configures the behavior of DuckDB-Wasm. By default, Framework sets the `castBigIntToDouble` and `castTimestampToDate` query options to true. To instead use [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt):
By default, `DuckDBClient.of` and `DuckDBClient.sql` automatically load all [configured extensions](#extensions). To change the loaded extensions for a particular `DuckDBClient`, use the **extensions** config option. For example, pass an empty array to instantiate a DuckDBClient with no loaded extensions (even if your configuration lists several):
Alternatively, you can configure extensions to be self-hosted but not load by default using the **duckdb** config option and the `load: false` shorthand:
172
+
173
+
```js run=false
174
+
exportdefault {
175
+
duckdb: {
176
+
extensions: {
177
+
spatial:false,
178
+
h3:false
179
+
}
180
+
}
181
+
};
182
+
```
183
+
184
+
You can then selectively load extensions as needed like so:
In the future, we’d like to allow DuckDB to be configured globally (beyond just [extensions](#extensions)) via the [**duckdb** config option](../config#duckdb); please upvote [#1791](https://github.com/observablehq/framework/issues/1791) if you are interested in this feature.
191
+
192
+
## Versioning
193
+
194
+
Framework currently uses [DuckDB-Wasm 1.29.0](https://github.com/duckdb/duckdb-wasm/releases/tag/v1.29.0), which aligns with [DuckDB 1.1.1](https://github.com/duckdb/duckdb/releases/tag/v1.1.1). You can load a different version of DuckDB-Wasm by importing `npm:@duckdb/duckdb-wasm` directly, for example:
However, you will not be able to change the version of DuckDB-Wasm used by SQL code blocks or the `sql` or `DuckDBClient` built-ins, nor can you use Framework’s support for self-hosting extensions with a different version of DuckDB-Wasm.
Copy file name to clipboardExpand all lines: docs/project-structure.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,7 +99,7 @@ For this site, routes map to files as:
99
99
/hello → dist/hello.html → src/hello.md
100
100
```
101
101
102
-
This assumes [“clean URLs”](./config#clean-urls) as supported by most static site servers; `/hello` can also be accessed as `/hello.html`, and `/` can be accessed as `/index` and `/index.html`. (Some static site servers automatically redirect to clean URLs, but we recommend being consistent when linking to your site.)
102
+
This assumes [“clean URLs”](./config#preserve-extension) as supported by most static site servers; `/hello` can also be accessed as `/hello.html`, and `/` can be accessed as `/index` and `/index.html`. (Some static site servers automatically redirect to clean URLs, but we recommend being consistent when linking to your site.)
103
103
104
104
Apps should always have a top-level `index.md` in the source root; this is your app’s home page, and it’s what people visit by default.
Copy file name to clipboardExpand all lines: docs/sql.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ sql:
29
29
30
30
<divclass="tip">For performance and reliability, we recommend using local files rather than loading data from external servers at runtime. You can use a <ahref="./data-loaders">data loader</a> to take a snapshot of a remote data during build if needed.</div>
31
31
32
-
You can also register tables via code (say to have sources that are defined dynamically via user input) by defining the `sql` symbol with [DuckDBClient.sql](./lib/duckdb).
32
+
You can also register tables via code (say to have sources that are defined dynamically via user input) by defining the `sql` symbol with [DuckDBClient.sql](./lib/duckdb). To register [DuckDB extensions](./lib/duckdb#extensions), use the [**duckdb** config option](./config#duckdb).
0 commit comments