Skip to content

Getting Started

import { Tabs, TabItem, Steps } from ‘@astrojs/starlight/components’;

SQLAnvil compiles SQLX files and action configs into SQL, then executes them against your data warehouse. Projects are driven by a workflow_settings.yaml file that declares your warehouse connection and default schema.

  • Node.js 20 LTS or later
  • One of: a BigQuery project with a service account, a PostgreSQL database, or a Supabase project
Terminal window
npm install -g @sqlanvil/cli

Or run without installing:

Terminal window
npx @sqlanvil/cli --help
  1. Initialize a new SQLAnvil project in an empty directory:

    Terminal window
    mkdir my-project && cd my-project
    sqlanvil init

    This creates:

    my-project/
    ├── definitions/ ← your SQLX and SQL files go here
    ├── includes/ ← shared JavaScript helpers
    └── workflow_settings.yaml
  2. Configure your warehouse by editing workflow_settings.yaml:

    ```yaml warehouse: kind: bigquery project: my-gcp-project location: US defaultDataset: analytics ``` ```yaml warehouse: kind: postgres host: localhost port: 5432 database: analytics user: sqlanvil_writer password: ${PG_PASSWORD} ssl: disable defaultSchema: public ``` ```yaml warehouse: kind: supabase projectRef: abcdefghijklmnop serviceRoleKey: ${SUPABASE_SERVICE_ROLE_KEY} defaultSchema: public ```
  3. Write your first action in definitions/my_view.sqlx:

    config {
    type: "view",
    description: "My first SQLAnvil view."
    }
    SELECT 1 AS id, 'hello' AS greeting
  4. Compile to inspect the SQL that will run:

    Terminal window
    sqlanvil compile
  5. Run against your warehouse:

    Terminal window
    sqlanvil run
PathPurpose
workflow_settings.yamlWarehouse connection, default schema/dataset, vars
definitions/SQLX files, SQL files, actions.yaml, JS files
includes/Shared JS macros and constants
package.jsonDeclares @sqlanvil/core version and any packages
TypeCreates
tableA full-replace table
viewA SQL view
incrementalAn incrementally-updated table
assertionA data quality test
operationArbitrary SQL statements
declarationA reference to an external table

See the Reference section in the sidebar for full API documentation on each action type.