Compare commits

...

2 commits

Author SHA1 Message Date
74b2291fe2 chore: release version v0.3.1
All checks were successful
continuous-integration/drone/push Build is passing
2023-10-02 02:29:20 +00:00
176b6bf0aa
fix: enable sorting capability.
All checks were successful
continuous-integration/drone/push Build is passing
2023-10-02 15:27:02 +13:00
6 changed files with 39 additions and 4 deletions

View file

@ -5,6 +5,15 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog --> <!-- changelog -->
## [v0.3.1](https://code.harton.nz/james/ash_cubdb/compare/v0.3.0...v0.3.1) (2023-10-02)
### Bug Fixes:
* enable sorting capability.
## [v0.3.0](https://code.harton.nz/james/ash_cubdb/compare/v0.2.0...v0.3.0) (2023-10-02) ## [v0.3.0](https://code.harton.nz/james/ash_cubdb/compare/v0.2.0...v0.3.0) (2023-10-02)

View file

@ -38,7 +38,7 @@ by adding `ash_cubdb` to your list of dependencies in `mix.exs`:
```elixir ```elixir
def deps do def deps do
[ [
{:ash_cubdb, "~> 0.3.0"} {:ash_cubdb, "~> 0.3.1"}
] ]
end end
``` ```

View file

@ -10,6 +10,7 @@ config :git_ops,
if Mix.env() in ~w[dev test]a do if Mix.env() in ~w[dev test]a do
config :ash_cubdb, ash_apis: [Support.Api] config :ash_cubdb, ash_apis: [Support.Api]
config :ash_cubdb, debug_data_layer_capabilities?: true
config :spark, :formatter, remove_parens?: true config :spark, :formatter, remove_parens?: true
end end

View file

@ -58,7 +58,17 @@ defmodule AshCubDB.DataLayer do
def can?(_, :filter), do: true def can?(_, :filter), do: true
def can?(_, {:filter_expr, _}), do: true def can?(_, {:filter_expr, _}), do: true
def can?(_, :boolean_filter), do: true def can?(_, :boolean_filter), do: true
def can?(_, _), do: false def can?(_, :sort), do: true
def can?(_, {:sort, _}), do: true
def can?(resource, capability) do
if Application.get_env(:ash_cubdb, :debug_data_layer_capabilities?, false) do
# credo:disable-for-next-line Credo.Check.Warning.Dbg
dbg(resource: resource, capability: capability)
end
false
end
@doc false @doc false
@impl true @impl true
@ -266,7 +276,7 @@ defmodule AshCubDB.DataLayer do
|> Runtime.filter_matches(records, query.filter, parent: parent) |> Runtime.filter_matches(records, query.filter, parent: parent)
end end
defp runtime_sort(records, query) do defp runtime_sort(records, query) when is_list(records) do
records = records =
records records
|> Sort.runtime_sort(query.distinct_sort || query.sort, api: query.api) |> Sort.runtime_sort(query.distinct_sort || query.sort, api: query.api)
@ -278,6 +288,8 @@ defmodule AshCubDB.DataLayer do
{:ok, records} {:ok, records}
end end
defp runtime_sort(records, query), do: records |> Enum.to_list() |> runtime_sort(query)
defp do_limit(records, :infinity), do: records defp do_limit(records, :infinity), do: records
defp do_limit(records, limit), do: Enum.take(records, limit) defp do_limit(records, limit), do: Enum.take(records, limit)
end end

View file

@ -1,7 +1,7 @@
defmodule AshCubDB.MixProject do defmodule AshCubDB.MixProject do
use Mix.Project use Mix.Project
@version "0.3.0" @version "0.3.1"
@moduledoc """ @moduledoc """
A CubDB data layer for `Ash` resources. A CubDB data layer for `Ash` resources.

View file

@ -127,6 +127,19 @@ defmodule AshCubDB.DataLayerTest do
assert expected.id == actual.id assert expected.id == actual.id
end end
test "sorting" do
insert!(Author, attrs: %{name: "Alice"})
insert!(Author, attrs: %{name: "Mallory"})
insert!(Author, attrs: %{name: "Bob"})
sorted =
Author
|> Query.sort(name: :desc)
|> Api.read!()
assert Enum.map(sorted, &to_string(&1.name)) == ["Mallory", "Bob", "Alice"]
end
end end
describe "update" do describe "update" do