ds_wrapper v0.1.1 DsWrapper.Datastore View Source
Link to this section Summary
Functions
Commit a transaction.
Remove entities from the Datastore.
Remove entities from the Datastore. Raises an exception on error.
Retrieve an entity by key.
Retrieve an entity by key. Raises an exception on error.
Retrieve the entities for the provided keys. The order of results is undefined and has no relation to the order of keys arguments.
Retrieve the entities for the provided keys. The order of results is undefined and has no relation to the order of keys arguments. Raises an exception on error.
Insert one or more entities to the Datastore.
Insert one or more entities to the Datastore. Raises an exception on error.
Rolls a transaction back.
Runs the given function inside a transaction. If the given function raises exception, rolled back the transaction.
Retrieve entities specified by a Query.
Retrieve entities specified by a Query. Raises an exception on error.
Creates a Datastore Transaction.
Update one or more entities to the Datastore.
Update one or more entities to the Datastore. Raises an exception on error.
Persist one or more entities to the Datastore.
Persist one or more entities to the Datastore. Raises an exception on error.
Link to this section Types
Link to this section Functions
commit(tx_connection)
View Sourcecommit(DsWrapper.Connection.t()) :: {:ok, GoogleApi.Datastore.V1.Model.CommitResponse.t()} | {:error, term()}
Commit a transaction.
Examples
iex> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> {:ok, tx} = DsWrapper.transaction(conn)
...> DsWrapper.Datastore.insert(tx, entity_a)
...> DsWrapper.Datastore.update(tx, entity_b)
...> DsWrapper.Datastore.commit(tx)
{:ok, %CommitResponse{...}}
delete(connection, keys)
View Sourcedelete(DsWrapper.Connection.t(), [key()] | key()) :: :ok | {:error, term()}
Remove entities from the Datastore.
Examples
iex> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> key = DsWrapper.Key.new("SomeKind", "some-name")
...> DsWrapper.Datastore.delete(connection, key)
:ok
delete!(connection, keys)
View Sourcedelete!(DsWrapper.Connection.t(), [key()] | key()) :: :ok | no_return()
Remove entities from the Datastore. Raises an exception on error.
find(connection, key)
View Sourcefind(DsWrapper.Connection.t(), key()) :: {:ok, map() | nil} | {:error, term()}
Retrieve an entity by key.
Examples
iex> import DsWrapper.Query
...> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> key = DsWrapper.Key.new("SomeKind", "some-name")
...> DsWrapper.Datastore.find(connection, key)
{:ok, %{...}}
find!(connection, key)
View Sourcefind!(DsWrapper.Connection.t(), key()) :: map() | nil | no_return()
Retrieve an entity by key. Raises an exception on error.
find_all(connection, keys)
View Sourcefind_all(DsWrapper.Connection.t(), [key()]) :: {:ok, find_all_result()} | {:error, term()}
Retrieve the entities for the provided keys. The order of results is undefined and has no relation to the order of keys arguments.
Examples
iex> import DsWrapper.Query
...> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> keys = [DsWrapper.Key.new("SomeKind", "some-name-01"), ...]
...> DsWrapper.Datastore.find_all(connection, keys)
{:ok, %{found: [%{...}, ...], missing: [%Key{...}, ...], deferred: [%Key{...}, ...]}}
find_all!(connection, keys)
View Sourcefind_all!(DsWrapper.Connection.t(), [key()]) :: find_all_result() | no_return()
Retrieve the entities for the provided keys. The order of results is undefined and has no relation to the order of keys arguments. Raises an exception on error.
insert(connection, entities)
View Sourceinsert( DsWrapper.Connection.t(), [GoogleApi.Datastore.V1.Model.Entity.t()] | GoogleApi.Datastore.V1.Model.Entity.t() ) :: {:ok, [key()] | nil} | {:error, term()}
Insert one or more entities to the Datastore.
Examples
iex> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> entity = DsWrapper.Entity.new(key, properties)
...> DsWrapper.Datastore.insert(connection, entity)
{:ok, [%Key{...}]}
insert!(connection, entities)
View Sourceinsert!( DsWrapper.Connection.t(), [GoogleApi.Datastore.V1.Model.Entity.t()] | GoogleApi.Datastore.V1.Model.Entity.t() ) :: [key()] | nil | no_return()
Insert one or more entities to the Datastore. Raises an exception on error.
rollback(tx_connection)
View Sourcerollback(DsWrapper.Connection.t()) :: :ok | {:error, term()}
Rolls a transaction back.
Examples
iex> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> {:ok, tx} = DsWrapper.transaction(conn)
...> DsWrapper.Datastore.insert(tx, entity_a)
...> DsWrapper.Datastore.update(tx, entity_b)
...> DsWrapper.Datastore.rollback(tx)
:ok
run_in_transaction(connection, fun)
View Sourcerun_in_transaction( DsWrapper.Connection.t(), (DsWrapper.Connection.t() -> term()) ) :: {:ok, term()} | {:error, term()}
Runs the given function inside a transaction. If the given function raises exception, rolled back the transaction.
Examples
iex> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> DsWrapper.run_in_transaction(conn, fn tx ->
...> Datastore.insert!(tx, entity)
...> Datastore.update!(tx, another_entity)
...> end)
{:ok, ...}
run_query(connection, query)
View Sourcerun_query(DsWrapper.Connection.t(), GoogleApi.Datastore.V1.Model.Query.t()) :: {:ok, query_result()} | {:error, term()}
Retrieve entities specified by a Query.
Examples
iex> import DsWrapper.Query
...> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> query = new_query("SomeKind") |> where("some_property", "=", "some value")
...> DsWrapper.Datastore.run_query(connection, query)
{:ok, %{cursor: ..., entities: [%{...}]}}
run_query!(connection, query)
View Sourcerun_query!(DsWrapper.Connection.t(), GoogleApi.Datastore.V1.Model.Query.t()) :: query_result() | no_return()
Retrieve entities specified by a Query. Raises an exception on error.
transaction(connection, opts \\ [read_only: nil, previous_transaction: nil])
View Sourcetransaction(DsWrapper.Connection.t(), read_only: boolean() | nil, previous_transaction: String.t() | nil ) :: {:ok, DsWrapper.Connection.t()} | {:error, term()}
Creates a Datastore Transaction.
Examples
iex> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> DsWrapper.transaction(conn)
{:ok, %DsWrapper.Connection{connection: ..., project_id: ..., transaction_id: ..., mutation_store_pid: ...}}
update(connection, entities)
View Sourceupdate( DsWrapper.Connection.t(), [GoogleApi.Datastore.V1.Model.Entity.t()] | GoogleApi.Datastore.V1.Model.Entity.t() ) :: {:ok, [key()] | nil} | {:error, term()}
Update one or more entities to the Datastore.
Examples
iex> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> entity = DsWrapper.Entity.new(key, properties)
...> DsWrapper.Datastore.update(connection, entity)
{:ok, [%Key{...}]}
update!(connection, entities)
View Sourceupdate!( DsWrapper.Connection.t(), [GoogleApi.Datastore.V1.Model.Entity.t()] | GoogleApi.Datastore.V1.Model.Entity.t() ) :: [key()] | nil | no_return()
Update one or more entities to the Datastore. Raises an exception on error.
upsert(connection, entities)
View Sourceupsert( DsWrapper.Connection.t(), [GoogleApi.Datastore.V1.Model.Entity.t()] | GoogleApi.Datastore.V1.Model.Entity.t() ) :: {:ok, [key()] | nil} | {:error, term()}
Persist one or more entities to the Datastore.
Examples
iex> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> entity = DsWrapper.Entity.new(key, properties)
...> DsWrapper.Datastore.upsert(connection, entity)
{:ok, [%Key{...}]}
upsert!(connection, entities)
View Sourceupsert!( DsWrapper.Connection.t(), [GoogleApi.Datastore.V1.Model.Entity.t()] | GoogleApi.Datastore.V1.Model.Entity.t() ) :: [key()] | nil | no_return()
Persist one or more entities to the Datastore. Raises an exception on error.