8000 GitHub - abc3/duckex: A naive DuckDB binding for Elixir via Rust port
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

abc3/duckex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Duckex

A naive DuckDB binding for Elixir via Rust port, primarily for testing DuckLake functionality.

Installation

Add duckex to your list of dependencies in mix.exs:

def deps do
  [
    {:duckex, github: "http://github.com/abc3/duckex"}
  ]
end

Quick Testing

For easier testing, use Elixir CLI:

make dev

Then in the IEx shell you can directly test the functions.

Usage

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")

Result Format

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
}

Error Format

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
}

Functions

  • Duckex.start_link/0 - Start the DuckDB process
  • Duckex.execute/1 - Execute SQL statements
  • Duckex.query/1 - Execute queries and return results

About

A naive DuckDB binding for Elixir via Rust port

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
0