View Source Ravix.Documents.Session (ravix v0.6.3)

A stateful session to execute RavenDB commands

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Marks the document for deletion

Executes a query into the RavenDB

Fetches the current session state

Callback implementation for GenServer.init/1.

Loads the document from the database to the local session

Persists the session changes to the RavenDB database

Executes a query in RavenDB and stream the response

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

delete(session_id, entity)

View Source
@spec delete(binary(), map() | binary()) :: any()

Marks the document for deletion

parameters

Parameters

  • session_id: the session id
  • entity/entity_id: the document to be deleted

returns

Returns

  • {:ok, Ravix.Documents.Session.State}
  • {:error, cause}
Link to this function

execute_query(query, session_id, method)

View Source
@spec execute_query(any(), binary(), any()) :: any()

Executes a query into the RavenDB

paremeters

Paremeters

  • query: The Ravix.RQL.Query to be executed
  • session_id: the session_id
  • method: The http method

Returns a RavenDB query response

@spec fetch_state(binary()) ::
  {:error, :session_not_found} | {:ok, Ravix.Documents.Session.State.t()}

Fetches the current session state

Returns a {:ok, Ravix.Documents.Session.State}

Link to this function

handle_continue(atom, state)

View Source

Callback implementation for GenServer.handle_continue/2.

Callback implementation for GenServer.init/1.

Link to this function

load(session_id, ids, includes \\ nil, opts \\ nil)

View Source
@spec load(binary(), list() | bitstring(), any(), keyword() | nil) :: any()

Loads the document from the database to the local session

parameters

Parameters

  • session_id: the session_id
  • ids: the document ids to be loaded
  • includes: the document includes path
  • opts: load options

returns

Returns

  • {:ok, results}
  • {:errors, cause}

examples

Examples

iex> Session.load(session_id, "entity_id")
    {:ok,
    %{
      "Includes" => %{},
      "Results" => [
        %{
          "@metadata" => %{
            "@change-vector" => "A:6450-HJrwf2z3c0G/FHJPm3zK3w",
            "@id" => "f13ffb17-ed7d-43b6-a483-23993db70958",
            "@last-modified" => "2022-04-23T11:14:16.4277047Z"
          },
          "cat_name" => "Coco",
          "id" => "f13ffb17-ed7d-43b6-a483-23993db70958"
        }
      ],
      "already_loaded_ids" => []
    }}
Link to this function

save_changes(session_id)

View Source
@spec save_changes(binary()) :: any()

Persists the session changes to the RavenDB database

Returns a RavenDB batch response

examples

Examples

iex> Session.save_changes(session_id)
    {:ok,
    %{
      "Results" => [
        %{
          "ChangeVector" => nil,
          "Deleted" => true,
          "Id" => "3421125e-416a-4bce-bb56-56cb4a7991ae",
          "Type" => "DELETE"
        }
      ]
    }}
Link to this function

start_link(attr, initial_state)

View Source
@spec start_link(any(), Ravix.Documents.Session.State.t()) ::
  :ignore | {:error, any()} | {:ok, pid()}
Link to this function

store(session_id, entity, key \\ nil, change_vector \\ nil, opts \\ [])

View Source
@spec store(binary(), map(), binary() | nil, binary() | nil, keyword()) :: any()

Add a document to the session to be created

parameters

Parameters

  • session_id: the session id
  • entity: the document to store
  • key: the document key to be used
  • change_vector: the concurrency change vector
  • opts: [ upsert: If the document is already loaded in the session, it should be upserted ]

returns

Returns

  • {:ok, Ravix.Documents.Session.State}
  • {:error, cause}
Link to this function

stream_query(query, session_id)

View Source
@spec stream_query(any(), binary()) :: Enumerable.t()

Executes a query in RavenDB and stream the response

paremeters

Paremeters

  • query: The Ravix.RQL.Query to be executed
  • session_id: the session_id
  • method: The http method

Returns a enumerable with the "Results" field of the RavenDB Query Response