DuckdbEx (DuckdbEx v0.2.0)

View Source

DuckDB Elixir Client - A 100% faithful port of the Python duckdb client.

This library provides Elixir bindings to DuckDB, an in-process SQL OLAP database management system. It mirrors the Python duckdb API for compatibility and ease of migration.

Reference: duckdb-python for API compatibility

Quick Start

# Connect to an in-memory database
{:ok, conn} = DuckdbEx.connect()

# Execute a query
{:ok, result} = DuckdbEx.execute(conn, "SELECT 42 as answer")

# Close the connection
DuckdbEx.close(conn)

Architecture

This implementation uses the DuckDB CLI binary managed through erlexec, providing a simpler alternative to NIF-based approaches while covering core SQL and Relation behaviors.

Modules

Future Modules (to be implemented)

  • DuckdbEx.Type - Type system
  • DuckdbEx.Expression - Expression helpers

Summary

Functions

close()

close(cursor)

Closes a database connection.

This is a convenience function that delegates to DuckdbEx.Connection.close/1.

Examples

{:ok, conn} = DuckdbEx.connect()
:ok = DuckdbEx.close(conn)

connect(database \\ :memory, opts \\ [])

Opens a connection to a DuckDB database.

This is a convenience function that delegates to DuckdbEx.Connection.connect/2.

Examples

{:ok, conn} = DuckdbEx.connect()
{:ok, conn} = DuckdbEx.connect(:memory)
{:ok, conn} = DuckdbEx.connect("/path/to/db.duckdb")

cursor()

cursor(conn)

default_connection()

Returns the current default connection, creating one if needed.

description()

duplicate()

duplicate(conn)

execute(sql_or_statement)

execute(conn, sql)

execute(conn, sql, params)

Executes a SQL query.

This is a convenience function that delegates to DuckdbEx.Connection.execute/3.

Examples

{:ok, conn} = DuckdbEx.connect()
{:ok, result} = DuckdbEx.execute(conn, "SELECT 1")

executemany(sql_or_statement)

executemany(conn, sql_or_statement)

executemany(conn, sql_or_statement, params_list)

extract_statements(sql)

fetchall()

fetchall(conn)

fetchmany()

fetchmany(conn)

fetchmany(conn, count)

fetchone()

fetchone(conn)

query(query)

query(conn, query)

query(conn, query, alias)

query(conn, query, alias, params)

read_csv(path)

read_csv(conn, path)

read_csv(conn, path, opts)

read_json(path)

read_json(conn, path)

read_json(conn, path, opts)

read_parquet(path)

read_parquet(conn, path)

read_parquet(conn, path, opts)

rowcount()

set_default_connection(conn)

Sets the default connection used by module-level helpers.

sql(query)

sql(conn, query)

sql(conn, query, params)

table(name)

table(conn, name)

values(values)

values(conn, values)

view(name)

view(conn, name)