AshScylla.DataLayer.MaterializedView (AshScylla v1.5.0)

Copy Markdown View Source

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.

Summary

Functions

Generates CQL for creating a materialized view.

Generates CQL for dropping a materialized view.

Returns the schema for the materialized view DSL options.

Validates a materialized view configuration.

Types

t()

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

Functions

create_view_cql(view_name, base_table, view_config)

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

Generates CQL for creating a materialized view.

drop_view_cql(view_name)

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

Generates CQL for dropping a materialized view.

schema()

@spec schema() :: keyword()

Returns the schema for the materialized view DSL options.

validate_view_config(view_config)

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

Validates a materialized view configuration.