Hi,
I’m new to Elixir. So sorry if I missed something.
I cannot make this query work:
alias Uniq.UUID
mandate_uuid = "6bf40047-117d-4056-b964-e54545f901ac"
mandate_uuid = UUID.string_to_binary!(mandate_uuid)
Repo.delete_all(
from(bp in BalancePoint,
where:
bp.date >= ^start_time and bp.date <= ^end_time and
bp.mandate_uuid == type(^mandate_uuid, :binary_id)
)
)
I ve got the following error:
value `<<107, 244, 0, 71, 17, 125, 64, 86, 185, 100, 229, 69, 69, 249, 1, 172>>`
cannot be dumped to type :binary_id in query
Here is my schema:
@primary_key false
@foreign_key_type :binary_id
schema "balances_points" do
field(:uuid, :binary_id, primary_key: true)
field(:date, :utc_datetime)
field(:asset, :string)
field(:mandate_uuid, :binary_id)
field(:total_quantity, :decimal)
timestamps()
end
The following code works with Postgrex :
alias Uniq.UUID
mandate_uuid = "6bf40047-117d-4056-b964-e54545f901ac"
mandate_uuid = UUID.string_to_binary!(mandate_uuid)
query = """
DELETE FROM balances_points
WHERE
date >= $2::timestamp
and date <= $3::timestamp
and mandate_uuid = $1;
"""
Ecto.Adapters.SQL.query(Repo, query, [mandate_uuid, start_time, end_time])
I don’t understand what’s wrong with Repo.delete_all
.
Thks