Cassandra.Ecto v0.1.1 Cassandra.Ecto.Adapter

Implements Ecto.Adapter behaviour.

Queries

Cassandra repo supports only following keywords for Ecto.Query.from/2:

:where
:order_by
:limit
:select
:preload

NOTE: don’t try to find :offset. It’s not supported by Cassandra.

NOTE: you should remember that by default in Cassandra it is not possible to filter and order by non primary key columns. To override this behaviour you could pass additional option allow_filtering: true. But it is not recommended, because of strong performance penalty. So it is very common to add extra tables that better fits specific queries, also you are free to create additional seconary indexes.

Repo.all((from p in Post, where: "abra" in p.tags), allow_filtering: true)

Upserts, updates and conditional inserts

By default in Cassandra insert and update both are equivalent to upsert. But Ecto by default expects that if record already exists it will raise error. So when Cassandra.Ecto executes insert it makes it conditional with IF NOT EXISTS to emulate Ecto default behaviour. To perform upsert with insert just use option on_conflict: :nothing.

Comparision table

Ecto function       on_conflict     Cassandra
-------------       -----------     ---------
insert/2            :raise          insert with 'IF NOT EXISTS'
insert/2            :nothing        insert/upsert
update/2            (no option)     update/upsert

Batched queries

Batched queries are done by Ecto.Repo.insert_all/3 with option batched: true. By default all batched queries runs in :logged mode. But it is possible to override this on two levels:

  1. Repo level, by setting :batch_mode repo option

    config :my_app, Repo,
      adapter: Cassandra.Ecto
      batch_mode: :unlogged
  2. Query level, by setting :batch_mode query option

    Repo.insert_all(Post, posts, on_conflict: :nothing, batched: true, batch_mode: :unlogged)

Available types:

:logged
:unlogged
:serial

Default type is :logged.

NOTE: don’t forget to set proper :on_conflict option.

Learn more about using batching in Using and misusing batches

Consistency

There are to options to configure consistency:

  1. Tunable consistency.

    Sets by :consistency option. Available types:

    :any
    :one
    :two
    :three
    :quorum
    :all
    :local_quorum
    :each_quorum

    Default type is :one.

  2. Linearizable consistency.

    Sets by :serial_consistency option. Available types:

    :serial
    :local_serial

    Default type is :undefined.

Every type of consistency can be set at repo and query level deparately.

Please see Consistency for more information.

TIMESTAMP and TTL

You can specify TTL and TIMESTAMP with :ttl and :timestamp respectively on query level.

Transactions

CASSANDRA DOESN’T SUPPORT TRANSACTIONS!

Summary

Functions

autogenerate(atom)

See Ecto.Adapter.autogenerate/1

delete(repo, meta, fields, opts)

See Ecto.Adapter.delete/4

dumpers(datetime, type)

See Ecto.Adapter.dumpers/2

execute(repo, map, arg, params, process, opts)

See Ecto.Adapter.execute/6

insert(repo, meta, fields, on_conflict, returning, opts)

See Ecto.Adapter.insert/6

insert_all(repo, meta, header, rows, on_conflict, returning, opts)

See Ecto.Adapter.insert_all/7

loaders(datetime, type)

See Ecto.Adapter.loaders/2

prepare(func, query)

See Ecto.Adapter.prepare/2

update(repo, meta, fields, filters, returning, opts)

See Ecto.Adapter.update/6