So I have my custom ULID implementation. It takes UUID format as well as BASE64 url encoded and transforms it to UUID in database layer. When taking out of DB it's transformed to BASE64 again. It creates shorter URLs which is nice. With ecto I needed just 2 lines of code to have all database IDs in this format. But I don't know what's the best way to do it in ash.
Also I've modified timestamps to be utc_datetime_usec instead of naive datetime ones. It's easier to convert them to different timezones that way.
Here's the code:
defmodule App.Schema do defmacro __using__(_env) do quote do use Ecto.Schema @timestamps_opts [ type: :utc_datetime_usec ] @primary_key {:id, App.Schema.ULID, autogenerate: true} @foreign_key_type App.Schema.ULID import Ecto.Changeset import Ecto.Query end endend
defmodule App.Schema do defmacro __using__(_env) do quote do use Ecto.Schema @timestamps_opts [ type: :utc_datetime_usec ] @primary_key {:id, App.Schema.ULID, autogenerate: true} @foreign_key_type App.Schema.ULID import Ecto.Changeset import Ecto.Query end endend
All I needed to do then was to
use App.Schema
use App.Schema
and it was done. Is there a similar way to do it in Ash? Or at least a way to add ULID in this convenient as a separate data type?
The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.