EtfPort

Runs a program that speaks the beamports protocol as an Erlang port: Erlang terms, each after a 4-byte length ({packet, 4}). duckport, oxiport and tantiport speak it when started with --etf, and so can any program built with the Rust crate beamports_etf, or that writes the same messages.

Installation

def deps do
  [
    {:etf_port, "~> 2.0"}
  ]
end

Usage

{:ok, pid} =
  EtfPort.start_link(
    executable: "/usr/local/bin/duckport",
    args: ["--etf", "--database", "/var/db/app/analytics.duckdb"],
    on_state: fn state -> IO.inspect(state, label: "duckport") end
  )

{:ok, %{"rows" => [%{"answer" => 42}]}} =
  EtfPort.call(pid, "query", %{sql: "SELECT 42 AS answer", params: []})

{:error, {:fail, "query_failed", %{"message" => _}}} =
  EtfPort.call(pid, "query", %{sql: "SELEKT", params: []})

{:error, "missing_sql"} = EtfPort.call(pid, "query", %{params: []})

Options of start_link/1:

EtfPort can be started under a supervisor as {EtfPort, options}.

Behaviour

License

BSD 3-Clause License, see the LICENSE file.