Skip to content

Instantly share code, notes, and snippets.

@srenatus
Created March 4, 2024 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srenatus/526df10ed15e18730584a2b1938cc0c4 to your computer and use it in GitHub Desktop.
Save srenatus/526df10ed15e18730584a2b1938cc0c4 to your computer and use it in GitHub Desktop.
custom SQL query page for Observable Framework + DuckDB

Custom Queries

const db = await DuckDBClient.of({
  table_one: FileAttachment("data/table_ond.parquet"),
  table_two: FileAttachment("data/table_two.parquet"),
});
const example = `select 1 as one
`;
const sqlInput = html`<textarea rows="12" style="width: 100%;">
${example}</textarea
>`;
const sql = Generators.input(sqlInput);
const tableOneSchema = db.query(`describe table_one`);
const tableTwoSchema = db.query(`describe table_two`);
const columns = ["column_name", "column_type"];
const response = db.query(sql);
${sqlInput}

Results

${response ? response.length : 0} rows ${Inputs.table(response)}

Table 1 Schema

${Inputs.table(tableOneSchema, { columns })}

Table 2 Schema

${Inputs.table(tableTwoSchema, { columns })}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment