View Source Ravix.Documents.Session (ravix v0.1.0)
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.handle_continue/2
.
Callback implementation for GenServer.init/1
.
Loads the document from the database to the local session
Persists the session changes to the RavenDB database
Add a document to the session to be created
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
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}
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}
Callback implementation for GenServer.handle_continue/2
.
Callback implementation for GenServer.init/1
.
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" => []
}}
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"
}
]
}}
@spec start_link(any(), Ravix.Documents.Session.State.t()) :: :ignore | {:error, any()} | {:ok, pid()}
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
returns
Returns
{:ok, Ravix.Documents.Session.State}
{:error, cause}