An elixir helper library for database list reordering functionality.
The package can be installed by adding reorderex
to your list of dependencies in mix.exs
:
def deps do
[
{:reorderex, "~> 0.2.0-beta"}
]
end
You can optionally add Reorderex.Clock
to supervision tree to make Reorderer.next_score
become strictly monotonic.
children = [
#...
Reorderex.Clock
#...
]
defmodule Photo do
@moduledoc false
use Ecto.Schema
schema "photos" do
field(:score, :binary, autogenerate: {Reorderex, :next_score, []})
end
end
import Reorderex.Ecto
photo
|> insert_after(photo1.id, Repo)
|> Repo.update()
import Reorderex.Ecto
photo
|> insert_after(nil, Repo)
|> Repo.update()
defmodule Photo do
@moduledoc false
use Ecto.Schema
schema "photos" do
field user_id, :binary
field :score, :binary, autogenerate: {Reorderex, :next_score, []}
end
end
import Reorderex.Ecto
query = Photo |> where([p], p.user_id = ^user_id)
photo
|> insert_after(photo1.id, Repo, query: query)
|> Repo.update()
The docs can be found at https://hexdocs.pm/reorderex.