DuckdbEx.Port (DuckdbEx v0.2.0)
View SourceManages the DuckDB CLI process using erlexec.
This module provides a simple wrapper around the DuckDB CLI binary, managing it as an OS process via erlexec. Communication happens through JSON-formatted commands and responses.
Architecture
Instead of using Rust NIFs, we use the DuckDB CLI in JSON mode to communicate with the database:
Elixir Process <--> erlexec <--> DuckDB CLI (JSON mode)This approach is simpler and avoids the complexity of NIF development while still providing full DuckDB functionality.
Summary
Functions
Returns a specification to start this module under a supervisor.
Executes a SQL query and returns the result.
Starts a DuckDB process.
Stops the DuckDB process.
Types
@type t() :: pid()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear_last_result(t()) :: :ok
Executes a SQL query and returns the result.
Examples
DuckdbEx.Port.execute(port, "SELECT 1 as num, 'hello' as text")
#=> {:ok, %{columns: ["num", "text"], rows: [{1, "hello"}]}}
@spec start_link(keyword()) :: GenServer.on_start()
Starts a DuckDB process.
Options
:database- Path to database file or:memory:(default::memory:):read_only- Open database in read-only mode (default:false)
Examples
{:ok, port} = DuckdbEx.Port.start_link()
{:ok, port} = DuckdbEx.Port.start_link(database: "/path/to/db.duckdb")
@spec stop(t()) :: :ok
Stops the DuckDB process.