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:
Repo level, by setting
:batch_mode
repo optionconfig :my_app, Repo, adapter: Cassandra.Ecto batch_mode: :unlogged
Query level, by setting
:batch_mode
query optionRepo.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:
Tunable consistency.
Sets by
:consistency
option. Available types::any :one :two :three :quorum :all :local_quorum :each_quorum
Default type is
:one
.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!