> For the complete documentation index, see [llms.txt](https://docs.slingdata.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.slingdata.io/concepts/build.md).

# Build

Sling Build is a lightweight SQL model builder built into the Sling CLI. It compiles Jinja-templated SQL models, resolves dependencies via a DAG, and executes them against any of Sling's 30+ supported database connectors. Think of it as a simpler alternative to dbt — no extra dependencies, no profiles, no packages — just SQL files and a single optional config.

{% hint style="success" %}
Sling Build integrates with the [Sling VSCode Extension](/sling-cli/vscode.md). The extension gives you schema validation, auto-completion, and diagnostics for your `sling_build.yml` configuration.
{% endhint %}

## Quick Start

### 1. Create a project

Write a `sling_build.yml` in the model folder. For a full Sling project, run `sling init`. That command writes `models/sling_build.yml`.

### 2. Add models

```
my_project/
├── sling_build.yml
├── staging/
│   ├── stg_orders.sql
│   └── stg_customers.sql
└── marts/
    └── fct_orders.sql
```

{% code title="sling\_build.yml" %}

```yaml
target: MY_POSTGRES

defaults:
  mode: full-refresh
```

{% endcode %}

{% code title="staging/stg\_orders.sql" %}

```sql
SELECT id, customer_id, amount, created_at
FROM raw_data.orders
```

{% endcode %}

{% code title="marts/fct\_orders.sql" %}

```sql
/**
mode: incremental
unique_key: id
update_key: created_at
**/

SELECT
    o.id,
    o.customer_id,
    o.amount,
    c.name as customer_name,
    o.created_at
FROM {{ ref('stg_orders') }} o
JOIN {{ ref('stg_customers') }} c ON o.customer_id = c.id
WHERE {{ incremental_where_cond() }}
```

{% endcode %}

### 3. Run the build

```bash
sling build
```

### 4. Preview without executing

```bash
sling build --compile
```

## Key Concepts

* [**Structure**](/concepts/build/structure.md) — Project layout, `sling_build.yml` configuration, naming conventions, dev & prod mode, selectors, multi-target projects.
* [**Models**](/concepts/build/models.md) — SQL model files, config declaration, materialization modes, template functions, macros, seeds, hooks, and data tests.
* [**Incremental**](/concepts/build/incremental.md) — Two styles (dbt-compatible and sling-native), the `range:` front-matter (lookback, paged mode), and `--range` CLI backfills.

## CLI Reference

```bash
sling build [path] [flags]
```

| Flag                | Short | Description                                                                                 |
| ------------------- | ----- | ------------------------------------------------------------------------------------------- |
| `path` (positional) |       | Project directory (default: current directory)                                              |
| `--target`          | `-t`  | Target connection (required if no `sling_build.yml`)                                        |
| `--select`          | `-s`  | Model selector (glob, `tag:xxx`, `+model` for upstream). Comma-separated for multiple       |
| `--exclude`         |       | Exclude models matching pattern. Comma-separated for multiple                               |
| `--full-refresh`    | `-f`  | Force full-refresh for all models                                                           |
| `--schema`          |       | Override dev schema (forces dev mode, cannot combine with `--prod`)                         |
| `--prod`            |       | Force prod mode (overrides `dev` block in yml)                                              |
| `--vars`            |       | Variables as YAML/JSON string                                                               |
| `--compile`         | `-c`  | Compile only — show SQL + DAG, don't execute                                                |
| `--list`            | `-l`  | List selected models and exit                                                               |
| `--fail-fast`       | `-x`  | Stop on first failure (in-flight models finish)                                             |
| `--no-seeds`        |       | Skip seed loading                                                                           |
| `--range`           |       | Backfill range for incremental models: `'start,end[,step]'`. Does not advance `SLING_STATE` |
| `--threads`         |       | Parallel model executions (default: 4)                                                      |
| `--recursive`       | `-R`  | Recursively discover `sling_build.yml` in immediate subdirectories                          |
| `--test`            |       | Run declarative data tests only (skip materialization)                                      |
| `--json`            |       | Emit machine-readable JSON for `--compile` / `--list`                                       |
| `--debug`           | `-d`  | Set logging level to DEBUG                                                                  |
| `--trace`           |       | Set logging level to TRACE                                                                  |

{% hint style="info" %}
If you give no `--target` and no `-R`, and the path has no `sling_build.yml`, `sling build` prints the help menu instead of walking the directory tree.
{% endhint %}

## Parallelism

Models run on a ready-queue: a model starts as soon as all of its selected dependencies complete. It does not wait for the full DAG level to finish.

* Default is 4 threads. Set `--threads` to change it.
* For single-writer targets (the DuckDB family), Sling forces 1 thread.
* With `--fail-fast`, models already in flight complete, but no new models start. Models that never started are reported as skipped.
* When a model fails, its downstream models are skipped, not failed.

## Examples

```bash
# Run all models in current directory
sling build

# Run specific models with 8 threads
sling build -s "stg_*" --threads 8

# Run a model and all its upstream dependencies
sling build -s "+fct_orders"

# Compile only — preview SQL and DAG without executing
sling build --compile

# Force full-refresh in production mode
sling build --prod --full-refresh

# Override target and pass variables
sling build -t MY_SNOWFLAKE --vars '{"start_date": "2024-01-01"}'

# List selected models without executing
sling build --list -s "tag:daily"

# Run data tests only, no materialization
sling build --test

# Machine-readable compile output
sling build --compile --json
```

## Build Step in Hooks and Pipelines

A build project can run as a step in a [pipeline](/concepts/pipeline.md) or as a [hook](/concepts/hooks.md), with `type: build`.

```yaml
steps:
  - type: build
    build: ./models
    target: MY_POSTGRES
    select: [ "tag:daily" ]
    threads: 4
```

| Key            | Type           | Description                                                                       |
| -------------- | -------------- | --------------------------------------------------------------------------------- |
| `build`        | string         | Project directory. Also becomes the working directory. Accepts a `file://` prefix |
| `target`       | string         | Target connection                                                                 |
| `select`       | string or list | Model selectors                                                                   |
| `exclude`      | string or list | Exclusion patterns                                                                |
| `vars`         | map            | Template variables                                                                |
| `schema`       | string         | Dev schema override                                                               |
| `prod`         | bool           | Force prod mode                                                                   |
| `full_refresh` | bool           | Force full-refresh                                                                |
| `no_seeds`     | bool           | Skip seeds                                                                        |
| `fail_fast`    | bool           | Stop on first failure                                                             |
| `threads`      | int            | Parallel model executions                                                         |
| `range`        | string         | Backfill range                                                                    |
| `recursive`    | bool           | Discover child `sling_build.yml` files                                            |
| `test`         | bool           | Run data tests only                                                               |

### Step State

The step publishes results to `state.<step_id>`:

| Field                       | Description                                                                                       |
| --------------------------- | ------------------------------------------------------------------------------------------------- |
| `path`                      | Resolved project directory                                                                        |
| `target`                    | Target connection name                                                                            |
| `results`                   | List of `{name, type, mode, duration, status, error}`. Status is `success`, `error`, or `skipped` |
| `total`                     | Model count                                                                                       |
| `ok` / `failed` / `skipped` | Counts by status                                                                                  |
| `ok_names`                  | Comma-joined names of successful models                                                           |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.slingdata.io/concepts/build.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
