diplomat v0.11.2 Diplomat.Entity
Link to this section Summary
Functions
Create a Diplomat.Entity
from a Diplomat.Proto.Entity
Creates a new Diplomat.Entity
with the given properties
Extract a Diplomat.Entity
's properties as a map
Generate a Diplomat.Proto.Entity
from a given Diplomat.Entity
. This can
then be used to generate the binary protocol buffer representation of the
Diplomat.Entity
Link to this section Types
mutation()
operation()
operation() :: :insert | :upsert | :update | :delete
operation() :: :insert | :upsert | :update | :delete
t()
t() :: %Diplomat.Entity{
key: Diplomat.Key.t() | nil,
kind: String.t() | nil,
properties: %{optional(String.t()) => Diplomat.Value.t()}
}
t() :: %Diplomat.Entity{ key: Diplomat.Key.t() | nil, kind: String.t() | nil, properties: %{optional(String.t()) => Diplomat.Value.t()} }
Link to this section Functions
extract_mutations(list, acc)
extract_mutations([mutation()], [Diplomat.Proto.Mutation.t()]) :: [
Diplomat.Proto.Mutation.t()
]
extract_mutations([mutation()], [Diplomat.Proto.Mutation.t()]) :: [ Diplomat.Proto.Mutation.t() ]
from_proto(entity)
from_proto(Diplomat.Proto.Entity.t()) :: t()
from_proto(Diplomat.Proto.Entity.t()) :: t()
Create a Diplomat.Entity
from a Diplomat.Proto.Entity
insert(entity)
insert([t()] | t()) :: [Diplomat.Key.t()] | Diplomat.Client.error()
insert([t()] | t()) :: [Diplomat.Key.t()] | Diplomat.Client.error()
new(props, kind_or_key_or_opts \\ [], id_or_opts \\ [], opts \\ [])
Creates a new Diplomat.Entity
with the given properties.
Instead of building a Diplomat.Enity
struct manually, new
is the way you
should create your entities. new
wraps and nests properties correctly, and
ensures that your entities have a valid Key
(among other things).
Options
:exclude_from_indexes
- An atom, list of atoms, or Keyword list of properties that will not be indexed.:truncate
- Boolean, whether or not to truncate string values that are over 1500 bytes (the max length of an indexed string in Datastore). Defaults tofalse
.:sanitize_keys
- Boolean or String. Iftrue
, dots (.
) in property keys will be replaced with an underscore (_
). If a string, dots will be replaced with the string passed. Defaults tofalse
.
Examples
Without a key
Entity.new(%{"foo" => "bar"})
With a kind but without a name or id
Entity.new(%{"foo" => "bar"}, "ExampleKind")
With a kind and name or id
Entity.new(%{"foo" => "bar"}, "ExampleKind", "1")
With a key
Entity.new(%{"foo" => "bar"}, Diplomat.Key.new("ExampleKind", "1"))
With excluded fields
Entity.new(%{"foo" => %{"bar" => "baz"}, "qux" => true},
exclude_from_indexes: [:qux, [foo: :bar]])
The above will exclude the :qux
field from the top level entity and the :bar
field from the entity nested at :foo
.
properties(entity)
Extract a Diplomat.Entity
's properties as a map.
The properties are stored on the struct as a map string keys and
Diplomat.Value
values. This function will allow you to extract the properties
as a map with string keys and Elixir built-in values.
For example, creating an Entity
looks like the following:
iex> entity = Entity.new(%{"hello" => "world"})
# => %Diplomat.Entity{key: nil, kind: nil,
# properties: %{"hello" => %Diplomat.Value{value: "world"}}}
Diplomat.Entity.properties/1
allows you to extract those properties to get
the following: %{"hello" => "world"}
proto(properties)
Generate a Diplomat.Proto.Entity
from a given Diplomat.Entity
. This can
then be used to generate the binary protocol buffer representation of the
Diplomat.Entity
upsert(entity)
upsert([t()] | t()) ::
{:ok, Diplomat.Proto.CommitResponse.t()} | Diplomat.Client.error()
upsert([t()] | t()) :: {:ok, Diplomat.Proto.CommitResponse.t()} | Diplomat.Client.error()