View Source Ravix.Documents.Session.State (ravix v0.10.0)

A session state representation

Fields

  • store: The Store module for which the session belongs
  • session_id: The uuid of this session
  • database: for which database this session belongs
  • conventions: Document conventions for this session
  • documents_by_id: Loaded documents in this session
  • defer_commands: Commands that will be deferred when the session is persisted
  • deleted_entities: Documents that will be deleted when the session is persisted
  • running_queries: RQL queries running for this session
  • last_session_call: When the last session call was executed
  • number_of_requests: Number os requests that will be executed at this session persistence

Summary

Functions

Clear the deferred commands from the session

Clear the deleted entities from the session

Fetches a document from the session

Increments the number of requests count

Marks a document to be deleted

Updates the last session call time

Updates the session with RavenDB responses

Types

@type t() :: %Ravix.Documents.Session.State{
  conventions: Ravix.Documents.Conventions.t(),
  database: String.t(),
  defer_commands: list(),
  deleted_entities: list(),
  documents_by_id: map(),
  last_session_call: DateTime.t() | nil,
  number_of_requests: non_neg_integer(),
  running_queries: map(),
  session_id: bitstring(),
  store: atom() | nil
}

Functions

Link to this function

clear_deferred_commands(state)

View Source
@spec clear_deferred_commands(t()) :: t()

Clear the deferred commands from the session

Link to this function

clear_deleted_entities(state)

View Source
@spec clear_deleted_entities(t()) :: t()

Clear the deleted entities from the session

Link to this function

fetch_document(state, document_id)

View Source
@spec fetch_document(t(), any()) :: {:error, :document_not_found} | {:ok, map()}

Fetches a document from the session

Parameters

  • state: the session state
  • document_id: the document id

Returns

  • {:ok, document}
  • {:error, :document_not_found} if there is no document with the informed id on the session
Link to this function

increment_request_count(session_state)

View Source
@spec increment_request_count(t()) :: t()

Increments the number of requests count

Parameters

  • session_state: the session state

Returns

  • updated session state
Link to this function

mark_document_for_exclusion(state, document_id)

View Source
@spec mark_document_for_exclusion(t(), bitstring()) :: {:error, atom()} | {:ok, t()}

Marks a document to be deleted

Parameters

  • state: the session state
  • document_id: the document id to be deleted

Returns

  • {:ok, state}
  • {:error, :document_already_deferred} if the document id is in a deferred command
  • {:error, :document_deleted} if the document is already marked for delete
  • {:error, :document_not_in_session} is the document is not loaded in the session
Link to this function

register_document(state, key, entity, change_vector, original_document \\ nil)

View Source

Adds a document to the session

Parameters

  • state: the session state
  • key: the key where the document will be related to
  • entity: the document to be persisted
  • change_vector: the concurrency change vector string
  • original_document: if it's a update, this is the document before the change

Returns

  • {:ok, updated_state}
  • {:error, :document_already_deferred} if the document id is in a deferred command
  • {:error, :document_deleted} if the document is marked for delete
Link to this function

update_last_session_call(session_state)

View Source
@spec update_last_session_call(t()) :: t()

Updates the last session call time

Parameters

  • session_state: the session state

Returns

  • updated session state
Link to this function

update_session(session_state, updates)

View Source
@spec update_session(t(), maybe_improper_list()) :: t()

Updates the session with RavenDB responses

Parameters

  • session_state: the session state
  • updates: List of updates to be applied to the session

Returns

  • the updated session