AshScylla.Connection (AshScylla v0.8.0)

Copy Markdown View Source

Direct Xandra connection wrapper for AshScylla.

Replaces the Exandra/Ecto.Repo pattern. Manages a Xandra connection process and provides query/prepare operations.

Usage

# In your application supervision tree:
children = [
  {AshScylla.Connection, name: MyApp.Scylla, nodes: ["127.0.0.1:9042"], keyspace: "my_app"}
]

# Or start manually:
{:ok, conn} = AshScylla.Connection.start_link(nodes: ["127.0.0.1:9042"], keyspace: "my_app")

Options

All options are passed through to Xandra.start_link/1. Key options:

  • :name - Register the connection under this name (required for supervised start)
  • :nodes - List of nodes, e.g. ["127.0.0.1:9042"]
  • :keyspace - Keyspace to USE on connect

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the connection struct by name (local or global).

Prepares a CQL statement.

Prepares a CQL statement, raising on error.

Executes a simple or prepared query.

Executes a simple or prepared query, raising on error.

Stops the connection.

Types

t()

@type t() :: %AshScylla.Connection{
  conn: pid(),
  keyspace: String.t() | nil,
  nodes: [String.t()]
}

Functions

child_spec(init_arg)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a specification to start this module under a supervisor.

See Supervisor.

get_conn(name \\ __MODULE__)

@spec get_conn(module() | atom()) :: t() | nil

Returns the connection struct by name (local or global).

prepare(conn_or_name, query, opts \\ [])

@spec prepare(t() | module(), String.t(), keyword()) ::
  {:ok, Xandra.Prepared.t()} | {:error, term()}

Prepares a CQL statement.

prepare!(conn_or_name, query, opts \\ [])

@spec prepare!(t() | module(), String.t(), keyword()) ::
  Xandra.Prepared.t() | no_return()

Prepares a CQL statement, raising on error.

query(conn_or_name, query, params, opts \\ [])

@spec query(t() | module(), String.t(), list(), keyword()) ::
  {:ok, term()} | {:error, term()}

Executes a simple or prepared query.

query!(conn_or_name, query, params, opts \\ [])

@spec query!(t() | module(), String.t(), list(), keyword()) :: term() | no_return()

Executes a simple or prepared query, raising on error.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

stop(name)

@spec stop(t() | module()) :: :ok

Stops the connection.