Advanced Topics
External DuckDB Instance
Section titled “External DuckDB Instance”By default, the widget creates its own shared DuckDB WASM instance. However, you can provide your own existing instance. This is useful if your application already uses DuckDB and you want to share data or minimize memory usage.
import * as duckdb from '@duckdb/duckdb-wasm';
// ... initialize your db instance ...const myDB = await duckdb.AsyncDuckDB.create(...);
// Pass it to the widgetPondPilot.create(element, { duckdbInstance: myDB, duckdbModule: duckdb});You can also pass a Promise that resolves to a DuckDB instance, and the widget will wait for it.
Relative Path Resolution
Section titled “Relative Path Resolution”The widget intelligently resolves file paths in your SQL.
-- Works even if the HTML file is in a subdirectorySELECT * FROM './data/sales.parquet';It handles:
./filerelative to current page./filerelative to domain root.file(no prefix) relative tobaseUrlconfiguration.
Geospatial Analysis
Section titled “Geospatial Analysis”You can use DuckDB’s spatial extensions within the widget. Use initQueries to load them.
PondPilot.config({ initQueries: [ "INSTALL spatial;", "LOAD spatial;", // Optional: Load community extensions "INSTALL a5 FROM community;", "LOAD a5;" ]});Map Visualization
Section titled “Map Visualization”Combine the pondpilot:results event with a mapping library like Leaflet to visualize geospatial queries.
- Run a query that outputs GeoJSON:
SELECT ST_AsGeoJSON(geom) as geojson FROM my_table;
- Listen for results:
document.addEventListener('pondpilot:results', (e) => {const rows = e.detail.data;// Parse GeoJSON strings and add to Leaflet maprows.forEach(row => {const feature = JSON.parse(row.geojson);L.geoJSON(feature).addTo(map);});});
See the Geospatial Demo for a complete example.