EctoMapSet (ecto_map_set v0.1.0) View Source

Typed MapSet support for Ecto.

The MapSets are backed by arrays in postgres. Currently untested in other database engines. A different package that backs the MapSets, untyped, with a map might be forthcoming.

Migration Example:

def change do
  create table(:my_sets) do
    add(:favorite_floats, {:array, :float})
  end
end

Schema Example:

def MySet do
  use Ecto.Schema
  schema "my_sets" do
    field :favorite_floats, EctoMapSet, of: :float
  end
end

Then when you retrieve your row, the data will be marshalled into a MapSet:

iex> Repo.get(MySet, id)
%MySet{favorite_floats: %MapSet<[47.0, 88.8]>}}

If you use an ecto changeset to marshal your data in, your mapset column may be any sort of enumerable. In most cases that will be a MapSet, a List, or a Stream.

NB: for PostgreSQL, if you are making a mapset of arrays, they must all have the same length. This is a limitation of PostgreSQL. This happens for a schema that looks like this:

schema "my_vectors" do
  field :vectors, EctoMapSet, of: {:array, :float}
end

Link to this section Summary

Link to this section Functions