DSL extensions for configuring ScyllaDB-specific options on Ash resources.
Usage
defmodule MyApp.MyResource do
use Ash.Resource,
data_layer: AshScylla.DataLayer
ash_scylla do
table "my_table"
keyspace "my_keyspace"
consistency :quorum
ttl 3600
# Define secondary indexes for non-primary key columns
secondary_index :email
secondary_index [:name, :age]
secondary_index :status, name: "idx_user_status"
lwt true # Enable lightweight transactions for atomic updates
end
attributes do
uuid_primary_key :id
attribute :name, :string
attribute :email, :string
attribute :status, :string
attribute :age, :integer
end
endOptions
:table- The table name in ScyllaDB (overrides default):keyspace- The keyspace to use (overrides repo default):consistency- The consistency level for reads/writes:ttl- Default TTL for inserted records (in seconds):lwt- Enable Lightweight Transactions (LWT) for atomic upserts usingINSERT ... IF NOT EXISTS(default:false):secondary_index- Define secondary indexes for non-primary key columns:materialized_view- Define materialized views with different primary key structure:pagination- Pagination mode::offset(default) or:tokenfor token-based pagination:per_action_consistency- Per-action consistency overrides as a keyword list, e.g.[read: :one, create: :quorum]
Features
The data layer supports:
- Upsert (
:upsert) - Insert-or-update semantics with optional LWT - Atomic updates (
{:atomic, :update}) - LWT-based conditional updates - Atomic upserts (
{:atomic, :upsert}) - LWT-based insert-or-update - Bulk update/destroy -
update_queryanddestroy_queryfor filtered operations - Distinct - On partition-key columns only
- Aggregates - COUNT via
:countaggregate - Expression calculations - In-memory post-processing
- Boolean filter - With OR-to-IN rewriting
Summary
Functions
Macro for configuring ScyllaDB options in Ash resources.
Gets the configured consistency level for a resource.
Checks if a column has a secondary index defined.
Gets the configured keyspace for a resource.
Gets the materialized views defined for a resource.
Gets the pagination mode for a resource.
Gets the per-action consistency configuration for a resource.
Gets the secondary indexes defined for a resource.
Gets the configured table name for a resource.
Gets the configured TTL for a resource.
Functions
Macro for configuring ScyllaDB options in Ash resources.
Examples
ash_scylla do
table "users"
keyspace "my_keyspace"
consistency :quorum
ttl 3600
# Define secondary indexes for non-primary key columns
secondary_index :email
secondary_index [:name, :age]
# Define materialized views
materialized_view :users_by_email,
primary_key: [:email, :id],
include_columns: [:name, :age]
pagination :token
per_action_consistency read: :one, create: :quorum
end
Gets the configured consistency level for a resource.
Checks if a column has a secondary index defined.
Gets the configured keyspace for a resource.
Gets the materialized views defined for a resource.
Returns a list of maps with keys:
:name- the view name (atom):config- the view configuration keyword list
@spec pagination(module()) :: :offset | :token
Gets the pagination mode for a resource.
Returns :offset or :token.
Gets the per-action consistency configuration for a resource.
Returns a map of action_name => consistency_level.
Gets the secondary indexes defined for a resource.
Returns a list of maps with keys:
:columns- list of column names (atoms):name- optional custom index name:options- additional options
Gets the configured table name for a resource.
@spec ttl(module()) :: pos_integer() | nil
Gets the configured TTL for a resource.