PPlusFireStore.Encoder (pplus_firestore v0.1.2)
View SourceDocumentation for PPlusFireStore.Encoder
.
The Google Firestore API expects a map in a complex format containing the data and their respective types.
The Encoder module is responsible for encoding the data to be sent.
Example:
iex> PPlusFireStore.Encoder.encode(%{"name" => "John Doe", "age" => 42})
%{
fields: %{
"name" => %{stringValue: "John Doe"},
"age" => %{integerValue: 42}
}
}
There are also special types such as DateTime
, GeoPoint
, and Reference
.
iex> PPlusFireStore.Encoder.encode(%{"name" => "John Doe", "age" => 42, "birth_data" => ~U[1998-06-02 09:30:01.023149Z]})
%{
fields: %{
"age" => %{integerValue: 42},
"birth_data" => %{timestampValue: %{seconds: 896779801, nanos: 23149000}},
"name" => %{stringValue: "John Doe"}
}
}
iex> PPlusFireStore.Encoder.encode(%{"location" => {:geo, {5.96989, 31.19063}}})
%{
fields: %{
"location" => %{geoPointValue: %{latitude: 5.96989, longitude: 31.19063}}
}
}
iex> PPlusFireStore.Encoder.encode(%{"location" => %{latitude: 5.96989, longitude: 31.19063}})
%{
fields: %{
"location" => %{geoPointValue: %{latitude: 5.96989, longitude: 31.19063}}
}
}
iex> PPlusFireStore.Encoder.encode(%{"next" => {:ref, "projects/my-project/databases/(default)/documents/my-collection/my-document"}})
%{
fields: %{
"next" => %{referenceValue: "projects/my-project/databases/(default)/documents/my-collection/my-document"}
}
}