Query Functions
Query functions allow you to operate on query results with SQL-like syntax.
Warning
Query functions are experimental and may change in the future
The supported query functions are:
Where
.where(`sqlStatement`)
Filters rows in the query based on the provided condition.
<DataTable data={orders.where(`sales > 100`)} />
Parameters
Required
A SQL-like condition to filter rows, must be wrapped in backticks.
Iterating through a query
```sql categories
SELECT DISTINCT category FROM orders
```
```sql orders_by_category
SELECT
category,
item,
sum(sales) as total_sales
FROM orders
group by all
```
{#each categories as category}
<BarChart data={orders_by_category.where(`category = '${category}'`)} />
{/each}
GroupBy
.groupBy([columns], withRowCount = true)
Groups rows by the specified columns and optionally includes a row count.
<DataTable data={orders.groupBy(["category", "item"])} />
Parameters
Required
The columns to group by.
Whether to include a `rows` column indicating the count of rows in each group.
Limit
.limit(limit)
Limits the number of rows returned by the query.
<DataTable data={orders.limit(5)} />
Parameters
Required
Maximum number of rows.
Offset
.offset(offset)
Skips a specified number of rows in the query result.
<DataTable data={orders.offset(20)} />
Parameters
Required
Number of rows to skip.
Agg
.agg({aggObj})
Adds aggregation operations to the query (e.g., sum
, avg
, min
, max
, median
). Used in conjunction with groupBy
.
<DataTable
data={orders.groupBy(["category", "item"]).agg({sum: "sales"})}
/>
Parameters
Required
Configuration object where keys are aggregation functions (sum
, avg
, min
, max
, median
) and values are column specifications.