Skip to content

referencing parameter values in sql front matter #1654

Answered by mbostock
c-koster asked this question in Q&A
Discussion options

You must be logged in to vote

The first option is that you can use a relative path. So if your page is at /products/[product]/index.md, you can have a data loader at /products/[product]/sales.csv.js that generates the sales data for that particular product, and then you can load the data as ./sales.csv. Because this is within the /products/[product]/ directory, the relative path to the data will be resolved to use the same parameter value.

A second option is to use DuckDBClient.sql to register the sources in JavaScript. This gives you a bit more flexibility since you can reference parameters.

```js
const sql = DuckDBClient.sql({
    product_sales: FileAttachment(`./data/product_sales_${observable.params.product}.csv`)…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@c-koster
Comment options

@mbostock
Comment options

Answer selected by c-koster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request
2 participants
Converted from issue

This discussion was converted from issue #1653 on September 12, 2024 04:15.