NebulaGraphEx.ResultSet (nebula_graph_ex v0.1.8)

Copy Markdown View Source

A decoded NebulaGraph result set with a convenient row/column API.

NebulaGraphEx.Graph.query/4 returns a %ResultSet{} on success. Each row is a %NebulaGraphEx.Record{} with fully decoded Elixir values.

Example

{:ok, rs} = NebulaGraphEx.Graph.query(conn, "MATCH (v:Player) RETURN v.name, v.age LIMIT 3")

rs |> NebulaGraphEx.ResultSet.columns()
#=> ["v.name", "v.age"]

rs |> NebulaGraphEx.ResultSet.count()
#=> 3

rs |> NebulaGraphEx.ResultSet.rows() |> Enum.map(&NebulaGraphEx.Record.to_map/1)
#=> [%{"v.name" => "Tim Duncan", "v.age" => 42}, ...]

Summary

Functions

Returns the ordered list of column name strings.

Returns the number of rows in the result set.

Returns true if the result set has no rows.

Returns the first %Record{}, or nil if the result set is empty.

Returns the first %Record{}, raising RuntimeError if the result is empty.

Server-side execution latency in microseconds.

Maps a function over every row. Equivalent to Enum.map(rows(rs), fun).

Returns the single row, raising if there is not exactly one.

Returns all rows as a list of %NebulaGraphEx.Record{} structs.

Returns all rows as a list of plain maps (%{column_name => value}).

Types

t()

@type t() :: %NebulaGraphEx.ResultSet{
  columns: [String.t()],
  comment: String.t() | nil,
  latency_us: non_neg_integer(),
  num_rows: non_neg_integer(),
  rows: [NebulaGraphEx.Record.t()],
  space_name: String.t() | nil,
  statement: String.t()
}

Functions

columns(result_set)

@spec columns(t()) :: [String.t()]

Returns the ordered list of column name strings.

count(result_set)

@spec count(t()) :: non_neg_integer()

Returns the number of rows in the result set.

empty?(arg1)

@spec empty?(t()) :: boolean()

Returns true if the result set has no rows.

first(result_set)

@spec first(t()) :: NebulaGraphEx.Record.t() | nil

Returns the first %Record{}, or nil if the result set is empty.

first!(result_set)

@spec first!(t()) :: NebulaGraphEx.Record.t()

Returns the first %Record{}, raising RuntimeError if the result is empty.

latency_us(result_set)

@spec latency_us(t()) :: non_neg_integer()

Server-side execution latency in microseconds.

map(result_set, fun)

@spec map(t(), (NebulaGraphEx.Record.t() -> term())) :: [term()]

Maps a function over every row. Equivalent to Enum.map(rows(rs), fun).

one!(result_set)

@spec one!(t()) :: NebulaGraphEx.Record.t()

Returns the single row, raising if there is not exactly one.

rows(result_set)

@spec rows(t()) :: [NebulaGraphEx.Record.t()]

Returns all rows as a list of %NebulaGraphEx.Record{} structs.

to_maps(rs)

@spec to_maps(t()) :: [%{required(String.t()) => term()}]

Returns all rows as a list of plain maps (%{column_name => value}).

Convenient for JSON serialisation or pattern matching on column names.