-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: insert funcions receive struct or changeset
- Loading branch information
1 parent
60c25aa
commit 95f5003
Showing
5 changed files
with
119 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule SwissSchemaTest.Book do | ||
@moduledoc false | ||
|
||
use Ecto.Schema | ||
use SwissSchema, repo: SwissSchemaTest.Repo | ||
import Ecto.Changeset | ||
|
||
schema "users" do | ||
field(:title, :string) | ||
field(:description, :string) | ||
end | ||
|
||
@impl SwissSchema | ||
def changeset(%SwissSchemaTest.Book{} = book, %{} = params) do | ||
book | ||
|> cast(params, [:title, :description]) | ||
|> validate_required([:title]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule SwissSchemaTest.CreateBooks do | ||
@moduledoc false | ||
|
||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:books) do | ||
add(:title, :string, null: false) | ||
add(:description, :string) | ||
end | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters