ds_wrapper v0.1.1 DsWrapper.Datastore View Source

GoogleApi.Datastore.V1.Api.Projects utility

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.

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 type

find_all_result()

View Source
find_all_result() :: %{
  found: [map()] | nil,
  missing: [key()] | nil,
  deferred: [key()] | nil
}
Link to this type

key()

View Source
key() :: %GoogleApi.Datastore.V1.Model.Key{partitionId: term(), path: term()}
Link to this type

query_result()

View Source
query_result() :: %{cursor: String.t() | nil, entities: [map()]}

Link to this section Functions

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{...}}
Link to this function

delete(connection, keys)

View Source
delete(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
Link to this function

delete!(connection, keys)

View Source
delete!(DsWrapper.Connection.t(), [key()] | key()) :: :ok | no_return()

Remove entities from the Datastore. Raises an exception on error.

Link to this function

find(connection, key)

View Source
find(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, %{...}}
Link to this function

find!(connection, key)

View Source
find!(DsWrapper.Connection.t(), key()) :: map() | nil | no_return()

Retrieve an entity by key. Raises an exception on error.

Link to this function

find_all(connection, keys)

View Source
find_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{...}, ...]}}
Link to this function

find_all!(connection, keys)

View Source

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.

Examples

iex> {:ok, connection} = DsWrapper.Connection.new("project-id")
...> entity = DsWrapper.Entity.new(key, properties)
...> DsWrapper.Datastore.insert(connection, entity)
{:ok, [%Key{...}]}

Insert one or more entities to the Datastore. Raises an exception on error.

See DsWrapper.Query.new_query/1.

Link to this function

rollback(tx_connection)

View Source
rollback(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
Link to this function

run_in_transaction(connection, fun)

View Source
run_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, ...}
Link to this function

run_query(connection, query)

View Source

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: [%{...}]}}

Retrieve entities specified by a Query. Raises an exception on error.

Link to this function

transaction(connection, opts \\ [read_only: nil, previous_transaction: nil])

View Source
transaction(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 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 one or more entities to the Datastore. Raises an exception on error.

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{...}]}

Persist one or more entities to the Datastore. Raises an exception on error.