View Source ReqTrino (ReqTrino v0.1.1)

Req plugin for Trino.

ReqTrino makes it easy to make Trino queries. Query results are decoded into the ReqTrino.Result struct. The struct implements the Table.Reader protocol and thus can be efficiently traversed by rows or columns.

Summary

Functions

Link to this function

attach(request, options \\ [])

View Source

Attaches to Req request.

Request Options

  • :host - Required. The Trino host.

  • :user - Required. The Trino user.

  • :password - Required. The Trino password.

  • :catalog - Required. The default catalog to connect.

  • :trino - Required. The query to execute.

Conditional fields must always be defined, and can be one of the fields or both.

If you want to set any of these options when attaching the plugin, pass them as the second argument.

Examples

With plain query string:

iex> opts = [
...>   user: System.fetch_env!("TRINO_USER"),
...>   password: System.fetch_env!("TRINO_PASSWORD"),
...>   catalog: System.fetch_env!("TRINO_CATALOG"),
...>   host: System.fetch_env!("TRINO_HOST")
...> ]
iex> query = "SELECT id, type, tags, members, timestamp, visible FROM planet WHERE id = 470454 and type = 'relation'"
iex> req = Req.new() |> ReqTrino.attach(opts)
iex> Req.post!(req, trino: query).body
%ReqTrino.Result{
  columns: ["id", "type", "tags", "members", "timestamp", "visible"],
  rows: [
    [470454, "relation",
     "{ref=17229A, site=geodesic, name=Mérignac A, source=©IGN 2010 dans le cadre de la cartographie réglementaire, type=site, url=http://geodesie.ign.fr/fiches/index.php?module=e&action=fichepdf&source=carte&sit_no=17229A, network=NTF-5}",
     "[{type=node, ref=670007839, role=}, {type=node, ref=670007840, role=}]",
     ~N[2017-01-21 12:51:34.000], true]
  ],
  statement_name: nil
}
Link to this function

build_req_params(request, opts)

View Source
Link to this function

decode_body(body, request_options)

View Source