Datasets
Define datasets and views in a project's Spicepod, then deploy them and query them with SQL.
A dataset is a table that Spice reads from a data source. A view is a SQL query over one or more datasets. You define both in the project's Spicepod.
Add a dataset
- In the project, go to Build > Code.
- In the Components sidebar, select a ready-to-use dataset on the Datasets tab, or a source on the Data Connectors tab.
- Click Save in the code toolbar, then click Deploy.
In spicepod.yaml, a dataset names its source in from and its table in name:
datasets:
- from: postgres:public.orders
name: orders
params:
pg_host: my-database.example.com
pg_db: mydb
pg_user: reader
pg_pass: ${secrets:PG_PASS}To keep a local copy of a dataset for fast queries, add an acceleration block. See Data Acceleration. For every source that Spice can read, see Data Connectors.
Add a view
A view names a SQL query. Query it as you query a dataset:
views:
- name: recent_orders
sql: SELECT * FROM orders WHERE created_at > now() - INTERVAL '1 day'Query a dataset
Open the Playground and run SQL against the dataset or view, or send SQL to the HTTP API.