use Ecto.Model queryable "users" do field :name, :string field :age, :string end validate user, name: present(), age: present(message: "must be present"), age: greater_than(18) end
:manual) and unless tags[:async] do Ecto.Adapters.SQL.restart_test_transaction(MyApp.Repo, []) end by :ok = Ecto.Adapters.SQL.Sandbox.checkout(MyApp.Repo) unless tags[:async] do Ecto.Adapters.SQL.Sandbox.mode(MyApp.Repo, {:shared, self()}) end
id}] = MyApp.Repo.insert_all("posts", [[title: "hello"]], returning: [:id]) # use query for updates post = from p in "posts", where: p.id == ^id {1, _} = MyApp.Repo.update_all(post, set: [title: "new title"]) # and deletes {1, _} = MyApp.Repo.delete_all post
|> cast(params, [:foo, :bar, :baz]) |> validate_required([:foo, :bar]) |> # some other validations |> to_tuple end defp to_tuple(%{valid?: true} = c) do {:ok, apply_changes(c)} end defp to_tuple(%{errors: errors}) do {:error, errors} end