improvement: support new ash select feature

This commit is contained in:
Zach Daniel 2021-04-09 00:53:50 -04:00
parent 026417f678
commit 737a6a5442
5 changed files with 29 additions and 3 deletions

View file

@ -18,7 +18,7 @@ jobs:
matrix:
otp: ["23"]
elixir: ["1.11.0"]
ash: ["master", "1.39.3"]
ash: ["master", "1.39.5"]
pg_version: ["9.5", "9.6", "11"]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View file

@ -262,6 +262,7 @@ defmodule AshPostgres.DataLayer do
def can?(_, :aggregate_filter), do: true
def can?(_, :aggregate_sort), do: true
def can?(_, :create), do: true
def can?(_, :select), do: true
def can?(_, :read), do: true
def can?(_, :update), do: true
def can?(_, :destroy), do: true
@ -760,6 +761,16 @@ defmodule AshPostgres.DataLayer do
end)
end
@impl true
def select(query, select, resource) do
query = default_bindings(query, resource)
{:ok,
from(row in query,
select: struct(row, ^select)
)}
end
@impl true
def distinct(query, distinct_on, resource) do
query = default_bindings(query, resource)

View file

@ -95,7 +95,7 @@ defmodule AshPostgres.MixProject do
{:ecto_sql, "~> 3.5"},
{:jason, "~> 1.0"},
{:postgrex, ">= 0.0.0"},
{:ash, ash_version("~> 1.39 and >= 1.39.3")},
{:ash, ash_version("~> 1.39 and >= 1.39.5")},
{:git_ops, "~> 2.0.1", only: :dev},
{:ex_doc, "~> 0.22", only: :dev, runtime: false},
{:ex_check, "~> 0.11.0", only: :dev},

View file

@ -1,5 +1,5 @@
%{
"ash": {:hex, :ash, "1.39.3", "249a1c7b7337b80f622433c594cee06c289f36a0dc924fe8ab7b8b3132efe093", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.3.5", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.1.5", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:timex, ">= 3.0.0", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "bd7ad8049ef0b39c868c62a6769e70ce10e5ee1771fe052a3b616b50835a7eb0"},
"ash": {:hex, :ash, "1.39.5", "95fc7860f5b15904d64b5bfc18237bde41bb9da68584287155adee613a1065ad", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.3.5", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.1.5", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:timex, ">= 3.0.0", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "20db450e1bcd8020d1aeef1d4c120ad4d2e23e0f9a92a6b6db8916600bf19b4e"},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},

15
test/select_test.exs Normal file
View file

@ -0,0 +1,15 @@
defmodule AshPostgres.SelectTest do
@moduledoc false
use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.{Api, Post}
require Ash.Query
test "values not selected in the query are not present in the response" do
Post
|> Ash.Changeset.new(%{title: "title"})
|> Api.create!()
assert [%{title: nil}] = Api.read!(Ash.Query.select(Post, :id))
end
end