Packages

NebulaGraph client for Elixir — connection pooling, session management, and rich result decoding.

Current section

Files

Jump to
nebula_graph_ex lib nebula_graph_ex result.ex
Raw

lib/nebula_graph_ex/result.ex

defmodule NebulaGraphEx.Result do
@moduledoc """
Raw execution result from NebulaGraph, as returned by `DBConnection`.
`NebulaGraphEx.Graph.query/4` wraps this into a `NebulaGraphEx.ResultSet`
before returning it to the caller. You only need this struct if you are
using `DBConnection` directly.
## Fields
* `:columns` — ordered list of binary column names
* `:rows` — list of raw value lists (each element is a `{tag, value}` tuple
as produced by `NebulaGraphEx.Thrift.Types.decode_value/1`)
* `:num_rows` — number of result rows
* `:latency_us` — server-side execution latency in microseconds
* `:space_name` — graph space name binary or `nil`
* `:comment` — server comment binary or `nil`
* `:statement` — the originating nGQL statement
"""
@type raw_value :: {atom(), term()}
@type t :: %__MODULE__{
columns: [String.t()],
rows: [[raw_value()]],
num_rows: non_neg_integer(),
latency_us: non_neg_integer(),
space_name: String.t() | nil,
comment: String.t() | nil,
statement: String.t()
}
defstruct columns: [],
rows: [],
num_rows: 0,
latency_us: 0,
space_name: nil,
comment: nil,
statement: ""
@doc false
def from_response(response, statement) do
dataset = response[:data]
columns = (dataset && dataset[:column_names]) || []
raw_rows = (dataset && dataset[:rows]) || []
%__MODULE__{
columns: columns,
rows: raw_rows,
num_rows: length(raw_rows),
latency_us: response[:latency_in_us] || 0,
space_name: response[:space_name],
comment: response[:comment],
statement: statement
}
end
end