PPlusFireStore.Encoder (pplus_firestore v0.1.5)

View Source

Documentation 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: ~U[1998-06-02 09:30:01.023149Z]},
    "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"}
  }
}

Summary

Functions

encode(value)

@spec encode(data :: map()) :: map()