Page MenuHomePhorge

No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/flake_id/ecto/type.ex b/lib/flake_id/ecto/type.ex
index c1ffa69..42c3bab 100644
--- a/lib/flake_id/ecto/type.ex
+++ b/lib/flake_id/ecto/type.ex
@@ -1,46 +1,46 @@
# FlakeID: Decentralized, k-ordered ID generation service
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: LGPL-3.0-only
-if Code.ensure_compiled?(Ecto.Type) do
- defmodule FlakeID.Ecto.Type do
- @moduledoc """
- Provides a type for Ecto usage.
+defmodule FlakeID.Ecto.Type do
+ @moduledoc """
+ Provides a type for Ecto usage.
- The underlying data type should be an `:uuid`.
+ The underlying data type should be an `:uuid`.
- ## Migration Example
+ ## Migration Example
- create table(:posts, primary_key: false) do
- add :id, :uuid, primary_key: true
- add :body, :text
- end
+ create table(:posts, primary_key: false) do
+ add :id, :uuid, primary_key: true
+ add :body, :text
+ end
- ## Schema Example
+ ## Schema Example
- @primary_key {:id, FlakeID.Ecto.Type, autogenerate: true}
+ @primary_key {:id, FlakeID.Ecto.Type, autogenerate: true}
- schema "posts" do
- add :body, :string
- end
+ schema "posts" do
+ add :body, :string
+ end
- """
- use Ecto.Type
+ """
+ @behaviour Ecto.Type
+ def embed_as(_), do: :self
+ def equal?(term1, term2), do: term1 == term2
- def type, do: :uuid
+ def type, do: :uuid
- defdelegate autogenerate, to: FlakeID, as: :get
+ defdelegate autogenerate, to: FlakeID, as: :get
- def cast(value) do
- {:ok, FlakeID.to_string(value)}
- end
+ def cast(value) do
+ {:ok, FlakeID.to_string(value)}
+ end
- def load(value) do
- {:ok, FlakeID.to_string(value)}
- end
+ def load(value) do
+ {:ok, FlakeID.to_string(value)}
+ end
- def dump(value) do
- {:ok, FlakeID.from_string(value)}
- end
+ def dump(value) do
+ {:ok, FlakeID.from_string(value)}
end
end

File Metadata

Mime Type
text/x-diff
Expires
Fri, Aug 28, 5:53 PM (19 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1735931
Default Alt Text
(1 KB)

Event Timeline