live_svelte/example_project/lib/example/note.ex
Denis Donici 6829effefd
Added better navigation between examples projects (#202)
* Added better navigation between examples projects. 
* Fix json date formatter
2026-02-01 00:14:15 +02:00

28 lines
721 B
Elixir

defmodule Example.Note do
@moduledoc """
Ecto schema for notes with UUID primary key.
This schema demonstrates how Ecto structs work with LiveSvelte's
OTP JSON encoder, which automatically converts structs to maps.
"""
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
schema "notes" do
field :title, :string
field :content, :string
field :color, :string, default: "#fef3c7"
timestamps(type: :utc_datetime)
end
@doc false
def changeset(note, attrs) do
note
|> cast(attrs, [:title, :content, :color])
|> validate_required([:title])
|> validate_length(:title, max: 100)
|> validate_length(:content, max: 1000)
end
end