Cassandrax.Schema behaviour (Cassandrax v0.4.0) View Source

Defines a schema.

This schema is used to map data fetched from a CassandraDB node into an Elixir struct.

Cassandrax.Schema mixin uses Ecto.Schema mixin.

Link to this section Summary

Functions

Defines an embedded schema for the Cassandra table with the given field definitions.

Callbacks

Converts a map of data into a struct for this module.

Link to this section Types

Link to this section Functions

Link to this macro

table(source, list)

View Source (macro)

Defines an embedded schema for the Cassandra table with the given field definitions.

In order to create a schema, you must define a @primary_key before the schema definition. Unlike Ecto.Schema, Cassandrax.Schema won't automatically generate a primary key which is named id. @primary_key configures the schema primary key and it expects a list of key(s). You can set a single primary key which is the partition key in Cassandra or a list of keys where the first key is the partition key and the rest are the clustering keys which are responsible for sorting data within the partition.

You can use Ecto's schema to leverage field definitions and metadata.

Example

  defmodule User do
    use Cassandrax.Schema

    @primary_key [:id]

    table "users" do
      field :id, :integer
      field :user_name, :string
    end
  end

Link to this section Callbacks

Specs

convert(data :: map() | nil) :: struct() | nil

Converts a map of data into a struct for this module.