A naive DuckDB binding for Elixir via Rust port, primarily for testing DuckLake functionality.
Add duckex
to your list of dependencies in mix.exs
:
def deps do
[
{:duckex, github: "http://github.com/abc3/duckex"}
]
end
For easier testing, use Elixir CLI:
make dev
Then in the IEx shell you can directly test the functions.
Start the process and execute queries:
# Start Duckex
{:ok, _pid} = Duckex.start_link()
# Install extensions
Duckex.execute("INSTALL ducklake")
Duckex.execute("INSTALL postgres")
# Attach DuckLake source
Duckex.execute("""
ATTACH 'ducklake:postgres:dbname=ducklake_catalog host=127.0.0.1 port=5432 password=postgres user=postgres'
AS my_ducklake (DATA_PATH 'data_files/')
""")
# Create table
Duckex.query("CREATE TABLE my_ducklake.my_demo_table (id INTEGER, name TEXT, created_at TIMESTAMP)")
# Insert data
Duckex.query("""
INSERT INTO my_ducklake.my_demo_table (id, name, created_at)
VALUES (2, 'Bob', CURRENT_TIMESTAMP), (3, 'Charlie', CURRENT_TIMESTAMP)
""")
# Query data
Duckex.query("SELECT * FROM my_ducklake.my_demo_table LIMIT 100")
Returns %Duckex.Result{}
struct:
%Duckex.Result{
message: "Query executed successfully",
columns: ["id", "name", "created_at"],
rows: [[2, "Bob", "Timestamp(...)"], [3, "Charlie", "Timestamp(...)"]],
num_rows: 2,
exec_time_ms: 9
}
Returns %Duckex.Error{}
struct on SQL errors:
Duckex.query("some unexisting sql")
%Duckex.Error{
message: "SQL preparation error: Parser Error: syntax error at or near \"some\"\n\nLINE 1: some unexisting sql\n ^",
exec_time_ms: 0
}
Duckex.start_link/0
- Start the DuckDB processDuckex.execute/1
- Execute SQL statementsDuckex.query/1
- Execute queries and return results