JsonlPort

Runs a program that speaks the beamports --jsonl request protocol as an Erlang port, and sends it one request at a time. duckport, oxiport and tantiport speak it when started with --jsonl, and so can any program that reads one JSON request per line and writes one JSON reply per line.

Installation

def deps do
  [
    {:jsonl_port, "~> 1.1"}
  ]
end

Usage

{:ok, pid} =
  JsonlPort.start_link(
    executable: "/usr/local/bin/duckport",
    args: ["--jsonl", "--database", "/var/db/app/analytics.duckdb"]
  )

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

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

Options of start_link/1:

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

Behaviour

The errors are listed in the module documentation (t:JsonlPort.error/0).

License

BSD 3-Clause License, see the LICENSE file.