blaze v0.1.1 Blaze.Document View Source
An interface to convert to and from GoogleApi.Firestore.V1.Model.Document
.
Create proper document structs by passing in primitive Elixir data types. You
may simply call encode/1
passing in a Map and a valid Document
model will
be returned.
Caveats
There are some data types that don't natively map between the expected Value types and native Elixir types. When decoding these values, whatever raw data is returned in the response is returned as-is. When encoding these values, developers must wrap them in a tuple with a special key to denote what kind of type they should be mapped to. Those types are:
:__firestore_bytes
: Maps thebytesValue
field.:__firestore_ref
: Maps thereferenceValue
field.:__firestore_geo
: Maps thegeoPointValue
field.:__firestore_time
: Maps thetimestampValue
field.
If you need to store raw bytes, a reference to another document, a geographic point, or a timestamp in a native format recognizable by Firestore then you must wrap those values in a tuple with the first element as one of the above corresponding keys. For example, to set a timestamp:
iex> encode_value({:__firestore_time, time_in_seconds})
%{timestampValue: %{seconds: time_in_seconds, nanos: 0}}
Link to this section Summary
Functions
Generate a map from a Document model.
Decodes a Document Value into a native Elixir term. If a tuple is given, a tuple is returned with the second element being decoded.
Generate a Document model from a map.
Encodes a native Elixir term into a Document Value. If a tuple is given, the first element is assumed to represent a key. If the key matches a reserved key, it applies special encoding rules. If not, it returns a tuple with the second element being encoded.
Link to this section Functions
decode(document)
View Sourcedecode(GoogleApi.Firestore.V1.Model.Document.t()) :: Map.t()
Generate a map from a Document model.
Decodes a Document Value into a native Elixir term. If a tuple is given, a tuple is returned with the second element being decoded.
encode(map)
View Sourceencode(Map.t()) :: GoogleApi.Firestore.V1.Model.Document.t()
Generate a Document model from a map.
encode_value(val)
View Sourceencode_value({term(), term()} | term()) :: {term(), GoogleApi.Firestore.V1.Model.Value.t()} | GoogleApi.Firestore.V1.Model.Value.t()
Encodes a native Elixir term into a Document Value. If a tuple is given, the first element is assumed to represent a key. If the key matches a reserved key, it applies special encoding rules. If not, it returns a tuple with the second element being encoded.
Read the module documentation (Caveats) for more information on the reserved keys and what rules are applied to each.