ExScylla

An Elixir wrapper around the scylla-rust-driver using Rustler.

Docs and api example found at: https://hexdocs.pm/ex_scylla

Prerequisites

Architecture & Performance

NIF/Rustler & Tokio Runtime

ExScylla uses Rustler to interface with the scylla-rust-driver. Because the Rust driver is heavily asynchronous and relies on the Tokio runtime, ExScylla spins up a dedicated Tokio runtime in the background to handle the driver's futures.

Resource Reference Model & Cloning

SessionBuilder, Session, and statements (Batch, Query, Prepared) use Arc references to the underlying Rust objects. These references are passed to Elixir as NIF resources.

Performance Note: Setter functions that mutate these objects will return a new reference to an updated copy (cloning the underlying Rust struct). As old instances are not immediately removed (waiting for Elixir GC), these mutating functions should be avoided in the hot path. It is better to create and configure the object once, then reuse it multiple times.

Async API & Timeouts

The library uses asynchronous NIFs for non-blocking operations to avoid starving the Erlang schedulers. By default, async NIF calls have a 5-second default timeout.

Dual API (Decoded vs Raw)

ExScylla provides a dual API approach:

Example

alias ExScylla.SessionBuilder
alias ExScylla.Session
alias ExScylla.Types.QueryResult

{:ok, session} = SessionBuilder.new()
                 |> SessionBuilder.known_node("127.0.0.1:9042")
                 |> SessionBuilder.build()
{:ok, ps} = Session.prepare(session, "INSERT INTO test.s_doc (a, b, c) VALUES (?, ?, ?)")
values = [{:text, "test"}, {:int, 2}, {:double, 1.0}]
{:ok, %QueryResult{}} = Session.execute(session, ps, values)

# Iterative queries (streams)
Session.query_stream(session, "SELECT * FROM test.s_doc", [])
|> Enum.each(fn row -> IO.inspect(row) end)

Installation

https://hex.pm/packages/ex_scylla

def deps do
  [
    {:ex_scylla, "~> 0.9.0"}
  ]
end

Contributing

We welcome contributions! Please see the CONTRIBUTING.md file for guidelines on how to contribute to this project.

Changelog

For a detailed list of changes and updates, please refer to the CHANGELOG.md file.