AshClickhouse.DataLayer.Dsl (AshClickhouse v0.3.0)

Copy Markdown View Source

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_byORDER BY expression for the table engine
  • :partition_byPARTITION 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)

Summary

Functions

The configured base_filter.

The configured database (overrides repo default).

The configured default_context.

The configured description.

The configured table engine.

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

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

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

The configured ORDER BY expression.

The configured PARTITION BY expression.

The configured explicit PRIMARY KEY columns.

The configured repo module.

The configured engine settings string.

The configured table name.

Functions

base_filter(resource)

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

The configured base_filter.

database(resource)

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

The configured database (overrides repo default).

default_context(resource)

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

The configured default_context.

description(resource)

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

The configured description.

engine(resource)

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

The configured table engine.

insert_opts(resource)

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

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

migrate?(resource)

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

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

mutations_sync(resource)

@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(resource)

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

The configured ORDER BY expression.

partition_by(resource)

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

The configured PARTITION BY expression.

primary_key(resource)

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

The configured explicit PRIMARY KEY columns.

repo(resource)

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

The configured repo module.

settings(resource)

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

The configured engine settings string.

table(resource)

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

The configured table name.