https://github.com/expressapp/ecto_crdt_types
Basic support for crdt types in ecto
https://github.com/expressapp/ecto_crdt_types
Last synced: 6 months ago
JSON representation
Basic support for crdt types in ecto
- Host: GitHub
- URL: https://github.com/expressapp/ecto_crdt_types
- Owner: ExpressApp
- License: mit
- Created: 2018-09-20T12:59:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-29T15:05:02.000Z (about 5 years ago)
- Last Synced: 2025-06-05T14:18:31.687Z (8 months ago)
- Language: Elixir
- Size: 70.3 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# EctoCrdtTypes [](https://travis-ci.org/ExpressApp/ecto_crdt_types) [](https://hex.pm/packages/ecto_crdt_types)
---
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](https://github.com/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`:
```elixir
def deps do
[{:ecto_crdt_types, "~> 0.4.0"}]
end
```
2. Ensure `ecto_crdt_types` is started before your application:
```elixir
def application do
[applications: [:ecto_crdt_types]]
end
```
## Usage
Define Ecto schema and changeset:
```elixir
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:
```elixir
iex> alias EctoCrdtTypes.Types.State.AWSet
iex> user =
%User{}
|> User.changeset(%{"name" => "My Name", "devices_crdt" => AWSet.new([]))
|> Repo.insert(user)
```