exduckdb

A quick-n-dirty Elixir DuckDB library.

Mostly true to the original fork of Exqlite, currently tracking version 0.3.1 of DuckDB through git submodules.

Implemented using the provided sqlite3_api_wrapper from DuckDB.

Caveats

Upstream Sqlite caveats

Installation

defp deps do
  {:exduckdb, "~> 0.9.0"}
end

Configuration

config :exduckdb, default_chunk_size: 100

Usage

The Exduckdb.DuckDB module usage is fairly straight forward.

# We'll just keep it in memory right now
{:ok, conn} = Exduckdb.DuckDB.open(":memory:")

# Create the table
:ok = Exduckdb.DuckDB.execute(conn, "create table test (id integer primary key, stuff text)");

# Prepare a statement
{:ok, statement} = Exduckdb.DuckDB.prepare(conn, "insert into test (stuff) values (?1)")
:ok = Exduckdb.DuckDB.bind(conn, statement, ["Hello world"])

# Step is used to run statements
:done = Exduckdb.DuckDB.step(conn, statement)

# Prepare a select statement
{:ok, statement} = Exduckdb.DuckDB.prepare(conn, "select id, stuff from test");

# Get the results
{:row, [1, "Hello world"]} = Exduckdb.DuckDB.step(conn, statement)

# No more results
:done = Exduckdb.DuckDB.step(conn, statement)

# Release the statement.
#
# It is recommended you release the statement after using it to reclaim the memory
# asap, instead of letting the garbage collector eventually releasing the statement.
#
# If you are operating at a high load issuing thousands of statements, it would be
# possible to run out of memory or cause a lot of pressure on memory.
:ok = Exduckdb.DuckDB.release(conn, statement)