View Source ReqTrino (ReqTrino v0.1.0)
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
Attaches to Req request.
Functions
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. It can be a plain sql string or a{query, params}tuple, wherequerycan contain?placeholders andparamsis a list of corresponding values.
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
}With parameterized query:
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 FROM planet WHERE id = ? and type = ?"
iex> req = Req.new() |> ReqTrino.attach(opts)
iex> Req.post!(req, trino: {query, [239_970_142, "node"]}).body
%ReqTrino.Result{
columns: ["id", "type"],
rows: [[239_970_142, "node"]],
statement_name: "query_C71EF77B8B7B92D9846C6D7E70136448"
}