Ecto Syntax Flashcards
1
Q
Repo.insert_all/3
A
MyRepo.insert_all(Post, [[title: “My first post”], [title: “My second post”]])
2
Q
Repo.insert/2 with do block
A
case MyRepo.insert %Post{title: “Ecto is great”} do
{:ok, struct} -> # Inserted with success
{:error, changeset} -> # Something went wrong
end
3
Q
Repo.insert/2, no do block
A
{:ok, inserted} = MyRepo.insert(%Post{title: “this is unique”})