# `AshClickhouse.DataLayer.Dsl`
[🔗](https://github.com/ohhi-vn/ash_clickhouse/blob/main/lib/ash_clickhouse/data_layer/dsl.ex#L1)

Runtime accessors for ClickHouse-specific options configured on Ash resources.

These functions read the configuration produced by the `clickhouse` DSL block
(see `AshClickhouse.DataLayer.Dsl.Macros`). They are intentionally kept in a
separate module from the `clickhouse` macro so that importing the macro module
does not also import these getters — that separation lets a resource define a
local helper named like a DSL key (e.g. `table/1`) without it being shadowed
by an imported getter.

## Usage

    defmodule MyApp.MyResource do
      use Ash.Resource,
        data_layer: AshClickhouse.DataLayer

      import AshClickhouse.DataLayer.Dsl.Macros

      clickhouse do
        table "my_table"
        repo MyApp.Repo
        database "my_app_dev"

        base_filter [status: "active"]
        default_context %{tenant: "org_123"}
        description "My resource description"

        engine "MergeTree()"
        order_by "id"
        partition_by "toYYYYMM(inserted_at)"

        settings "index_granularity = 8192"
      end

      attributes do
        uuid_primary_key :id
        attribute :name, :string
      end
    end

## Options

- `:table` — the table name in ClickHouse (overrides the default)
- `:repo` — the `AshClickhouse.Repo` module to use
- `:database` — the database to use (overrides repo default)
- `:engine` — the ClickHouse table engine (default `"MergeTree()"`)
- `:order_by` — `ORDER BY` expression for the table engine
- `:partition_by` — `PARTITION BY` expression for the table engine
- `:primary_key` — explicit primary key columns (ClickHouse `PRIMARY KEY`)
- `:settings` — engine settings string
- `:base_filter` — a filter applied to all queries on this resource
- `:default_context` — context merged into every query/changeset
- `:description` — human-readable description of the resource
- `:migrate` — whether this resource is included in migrations (default `true`)
- `:insert_opts` — options applied to bulk inserts (e.g. `async_insert: 1`)
- `:mutations_sync` — default `mutations_sync` for ALTER mutations (`1`/`2`/`nil`)
- `:index` — repeated; declares a data-skipping index (see `clickhouse do ... end`)

# `base_filter`

```elixir
@spec base_filter(module()) :: term() | nil
```

The configured base_filter.

# `database`

```elixir
@spec database(module()) :: String.t() | nil
```

The configured database (overrides repo default).

# `default_context`

```elixir
@spec default_context(module()) :: map() | nil
```

The configured default_context.

# `description`

```elixir
@spec description(module()) :: String.t() | nil
```

The configured description.

# `engine`

```elixir
@spec engine(module()) :: String.t()
```

The configured table engine.

# `indexes`

```elixir
@spec indexes(module()) :: [map()]
```

The configured data-skipping indexes.

# `insert_opts`

```elixir
@spec insert_opts(module()) :: keyword()
```

Options applied to bulk inserts for this resource (e.g.
`async_insert: 1, wait_for_async_insert: 1`).

# `migrate?`

```elixir
@spec migrate?(module()) :: boolean()
```

Whether this resource is included in migrations (default `true`).

# `mutations_sync`

```elixir
@spec mutations_sync(module()) :: nil | 1 | 2
```

The default `mutations_sync` value for ALTER TABLE mutations on this resource
(1 = wait on current replica, 2 = wait on all replicas, nil = async).

# `order_by`

```elixir
@spec order_by(module()) :: String.t() | nil
```

The configured ORDER BY expression.

# `partition_by`

```elixir
@spec partition_by(module()) :: String.t() | nil
```

The configured PARTITION BY expression.

# `primary_key`

```elixir
@spec primary_key(module()) :: [atom()] | nil
```

The configured explicit PRIMARY KEY columns.

# `repo`

```elixir
@spec repo(module()) :: module() | nil
```

The configured repo module.

# `settings`

```elixir
@spec settings(module()) :: String.t() | nil
```

The configured engine settings string.

# `table`

```elixir
@spec table(module()) :: String.t() | nil
```

The configured table name.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
