ExpressApp/ecto_crdt_types


Basic support for crdt types in ecto

License: MIT

Language: Elixir


EctoCrdtTypes Build Status Hex.pm


Libary provides support for saving CRDT data and values to db using Ecto.

It provides:

  • changeset function cast_crdt,
  • Ecto.Schema macro crdt_field
  • custom Ecto types, with generic support of lasp-lang/types library underneath.

Currently we actively use the following types from lasp-lang:

  • :state_awset
  • :state_lwwregistry

Other types have very basic support. So feel free to contribute!


Installation

  1. Add ecto_crdt_types to your list of dependencies in mix.exs:
def deps do
  [{:ecto_crdt_types, "~> 0.4.0"}]
end
  1. Ensure ecto_crdt_types is started before your application:
def application do
  [applications: [:ecto_crdt_types]]
end

Usage

Define Ecto schema and changeset:

defmodule User do
  use Ecto.Schema
  import EctoCrdtTypes.Fields

  alias EctoCrdtTypes.Types.State.AWSet

  schema "users" do
    field :name, :string
    crdt_field :devices, AWSet
  end

  def changeset(model, params) do
    params
    |> cast(params, [:name])
    |> cast_crdt([:devices])
  end
end

Initialize new User changeset:

iex> alias EctoCrdtTypes.Types.State.AWSet

iex> user =
%User{}
|> User.changeset(%{"name" => "My Name", "devices_crdt" => AWSet.new([]))
|> Repo.insert(user)

Project Statistics

Sourcerank 4
Repository Size 46.9 KB
Stars 4
Forks 0
Watchers 2
Open issues 0
Dependencies 17
Contributors 1
Tags 0
Created
Last updated
Last pushed

Top Contributors See all

Alexander Malaev

Packages Referencing this Repo

ecto_crdt_types
Library providing support for saving CRDT data and values to db using Ecto.
Latest release 0.4.0 - Updated - 4 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-09-11 12:25:36 UTC

Login to resync this repository