# `AshScylla.DataLayer.MaterializedView`
[🔗](https://github.com/ohhi-vn/ash_scylla/blob/main/lib/ash_scylla/data_layer/materialized_view.ex#L15)

Materialized view support for AshScylla.

Materialized views in ScyllaDB/Cassandra allow you to define a view with a
different primary key structure from the base table. This enables efficient
queries on non-primary key columns without using secondary indexes.

## Usage

Define a materialized view in your resource DSL:

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

      scylla do
        table "users"
        materialized_view :users_by_email,
          primary_key: [:email, :id],
          include_columns: [:name, :age]
      end
    end

This will generate:

    CREATE MATERIALIZED VIEW IF NOT EXISTS users_by_email
    AS SELECT id, email, name, age
    FROM users
    WHERE email IS NOT NULL AND id IS NOT NULL
    PRIMARY KEY (email, id)
    WITH CLUSTERING ORDER BY (id ASC)

## Options

- `:primary_key` — Required. The primary key columns for the view.
- `:include_columns` — Additional columns to include (besides PK).
- `:clustering_order` — Clustering column ordering (e.g., `[id: :desc]`).
- `:where_clause` — Custom WHERE clause for NOT NULL constraints.

# `t`

```elixir
@type t() :: %{
  name: atom(),
  primary_key: [atom()],
  clustering_order: keyword(),
  include_columns: [atom()],
  where_clause: String.t() | nil
}
```

# `create_view_cql`

```elixir
@spec create_view_cql(atom(), String.t(), keyword()) :: String.t()
```

Generates CQL for creating a materialized view.

# `drop_view_cql`

```elixir
@spec drop_view_cql(atom()) :: String.t()
```

Generates CQL for dropping a materialized view.

# `schema`

```elixir
@spec schema() :: keyword()
```

Returns the schema for the materialized view DSL options.

# `validate_view_config`

```elixir
@spec validate_view_config(keyword()) :: :ok | {:error, String.t()}
```

Validates a materialized view configuration.

---

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