Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

ertgl/ecto_json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Packages

No packages published