Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ecto.JSON makes Ecto able to use any type of data (Integer, String, List, Map, etc.) which is valid JSON, not only key-value maps.

Hex Version Docs Hex downloads GitHub MIT License

Installation

The package is available in Hex, it can be installed by adding :ecto_json to your list of dependencies in mix.exs:

def deps do
  [
    {:ecto_json, "~> 0.1.0"},
  ]
end

Usage

The package is available in Hex, it can be installed by adding :ecto_json to your list of dependencies in mix.exs:

defmodule Property do

  use Ecto.Schema

  import Ecto.Changeset

  @primary_key {:id, :binary_id, autogenerate: true}
  @foreign_key_type :binary_id
  schema "properties" do
    field :key, :string
    field :value, Ecto.JSON

    timestamps([
      type: :utc_datetime,
    ])
  end

  def changeset(property, attrs) do
    property
    |> cast(attrs, [:key, :value])
    |> validate_required([:key, :value])
  end

end

About

Ecto.JSON makes Ecto able to use any type of data (Integer, String, etc.) which is valid JSON, not only key-value maps.

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages