2022-05-19 05:21:58 +12:00
|
|
|
defmodule AshPostgres.Test.TypeTest do
|
|
|
|
use AshPostgres.RepoCase, async: false
|
2024-03-28 09:52:28 +13:00
|
|
|
alias AshPostgres.Test.Post
|
2022-05-19 05:21:58 +12:00
|
|
|
|
|
|
|
require Ash.Query
|
|
|
|
|
|
|
|
test "complex custom types can be used" do
|
|
|
|
post =
|
|
|
|
Post
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.Changeset.for_create(:create, %{title: "title", point: {1.0, 2.0, 3.0}})
|
|
|
|
|> Ash.create!()
|
2022-05-19 05:21:58 +12:00
|
|
|
|
|
|
|
assert post.point == {1.0, 2.0, 3.0}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "complex custom types can be accessed with fragments" do
|
|
|
|
Post
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.Changeset.for_create(:create, %{title: "title", point: {1.0, 2.0, 3.0}})
|
|
|
|
|> Ash.create!()
|
2022-05-19 05:21:58 +12:00
|
|
|
|
|
|
|
Post
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.Changeset.for_create(:create, %{title: "title", point: {2.0, 1.0, 3.0}})
|
|
|
|
|> Ash.create!()
|
2022-05-19 05:21:58 +12:00
|
|
|
|
|
|
|
assert [%{point: {2.0, 1.0, 3.0}}] =
|
|
|
|
Post
|
|
|
|
|> Ash.Query.filter(fragment("(?)[1] > (?)[2]", point, point))
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.read!()
|
2022-05-19 05:21:58 +12:00
|
|
|
end
|
2022-10-18 02:40:32 +13:00
|
|
|
|
|
|
|
test "uuids can be used as strings in fragments" do
|
|
|
|
uuid = Ash.UUID.generate()
|
|
|
|
|
|
|
|
Post
|
|
|
|
|> Ash.Query.filter(fragment("? = ?", id, type(^uuid, :uuid)))
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.read!()
|
2022-10-18 02:40:32 +13:00
|
|
|
end
|
2022-05-19 05:21:58 +12:00
|
|
|
end
|