AshScylla.DataLayer.MaterializedView (AshScylla v0.2.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

  ash_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)

Summary

Functions

Generates CQL for creating a materialized view.

Generates CQL for dropping a materialized view.

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.

validate_view_config(view_config)

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

Validates a materialized view configuration.