mit einem Klick
bootstrap
// Bootstrap a semantic layer from a database. Use when the user wants to create .view.yml files from their warehouse schema, or when starting a new airlayer project from scratch.
// Bootstrap a semantic layer from a database. Use when the user wants to create .view.yml files from their warehouse schema, or when starting a new airlayer project from scratch.
| name | bootstrap |
| description | Bootstrap a semantic layer from a database. Use when the user wants to create .view.yml files from their warehouse schema, or when starting a new airlayer project from scratch. |
You are bootstrapping a semantic layer for airlayer. This means discovering what's in the user's database and generating .view.yml files that define dimensions, measures, and entities.
The user needs a config.yml with database connection details. If they don't have one, help them create it. The format is:
databases:
- name: <name>
type: <postgres|snowflake|bigquery|duckdb|motherduck|mysql|clickhouse|databricks|sqlite>
# ... connection fields vary by type (see docs/agent-execution.md)
MotherDuck example:
databases:
- name: cloud
type: motherduck
token_var: MOTHERDUCK_TOKEN
database: my_db
airlayer must be built with executor support: cargo build --features exec (or a specific driver like exec-postgres).
Run schema introspection to discover all tables, columns, and types:
airlayer inspect --schema --config <config.yml>
Optionally filter to a specific schema/dataset:
airlayer inspect --schema <schema_name> --config <config.yml>
This returns JSON with every table and column. Read the output carefully — it's your source of truth for what's available.
Present the discovered tables to the user and ask which ones they want in the semantic layer. Don't model everything — focus on the tables they care about for analytics.
For each selected table, create a .view.yml file in the project directory. Follow these rules:
Dimensions (attributes to group/filter by):
type: stringtype: datetype: datetimetype: booleantype: string or type: numberMeasures (aggregations):
type: count (no expr needed)type: count_distinct with expr: <column>type: sum with expr: <column>type: average with expr: <column>type: sum with expr: "quantity * price" etc.Entities (join keys):
type: primary, key: <column>type: foreign, key: <column>customer, order), not the column nameNaming conventions:
name: should be snake_case, semantic (e.g., total_revenue not sum_amount)expr: is the raw SQL expression — reference actual column names from the schemadescription: add for any non-obvious measures or computed fieldsExample view:
name: orders
description: "Sales orders with customer and product data"
dialect: postgres
datasource: warehouse
table: public.orders
entities:
- name: customer
type: foreign
key: customer_id
dimensions:
- name: order_id
type: string
expr: order_id
- name: status
type: string
expr: status
- name: created_at
type: datetime
expr: created_at
measures:
- name: order_count
type: count
- name: total_revenue
type: sum
expr: amount
After creating views, profile them to verify the data looks right:
# Profile all dimensions in a view
airlayer inspect --profile <view_name> --config <config.yml>
# Profile a single dimension
airlayer inspect --profile <view_name>.<dimension_name> --config <config.yml>
Review the profile output:
Run a few test queries to validate the semantic layer:
airlayer query --execute --config <config.yml> \
--dimension <view>.<dim> --measure <view>.<measure>
Check the envelope:
status: "success" → the view workssql → does the generated SQL look correct?data → are the values reasonable?If something's wrong:
expr → fix the expr, re-rundialect field must match the database type (postgres, snowflake, bigquery, duckdb, motherduck, mysql, clickhouse, databricks, redshift, sqlite)duckdb dialect — set dialect: duckdb in views that target MotherDuckdatasource field must match a database name in config.ymltable field is the actual table name in the database (can be schema-qualified like public.orders)customer)Run a semantic query against the database via airlayer. Use when the user wants to query data through the semantic layer, test view definitions, or debug query results.
Migrate a Cube.js semantic layer to airlayer .view.yml files. Use when the user has existing Cube.js schema files (.js or .yml) they want to convert to airlayer format.
Profile dimensions in the semantic layer to discover data values, ranges, and cardinality. Use when the user wants to understand what data is in a dimension, find valid filter values, or validate view definitions against actual data.
Inspect semantic layer views, dimensions, measures, and entities. Use when the user wants to explore what's available in their .view.yml files or understand the schema structure.
Compile a semantic query to SQL using airlayer. Use when the user wants to generate SQL from .view.yml schemas, test a query against their semantic layer, or translate dimensions/measures/filters into dialect-specific SQL.
Validate .view.yml semantic layer files using airlayer. Use when the user creates or modifies view files and wants to check for errors.