Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
74b2291fe2 | |||
176b6bf0aa |
6 changed files with 39 additions and 4 deletions
|
@ -5,6 +5,15 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
|
|||
|
||||
<!-- 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)
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ by adding `ash_cubdb` to your list of dependencies in `mix.exs`:
|
|||
```elixir
|
||||
def deps do
|
||||
[
|
||||
{:ash_cubdb, "~> 0.3.0"}
|
||||
{:ash_cubdb, "~> 0.3.1"}
|
||||
]
|
||||
end
|
||||
```
|
||||
|
|
|
@ -10,6 +10,7 @@ config :git_ops,
|
|||
|
||||
if Mix.env() in ~w[dev test]a do
|
||||
config :ash_cubdb, ash_apis: [Support.Api]
|
||||
config :ash_cubdb, debug_data_layer_capabilities?: true
|
||||
|
||||
config :spark, :formatter, remove_parens?: true
|
||||
end
|
||||
|
|
|
@ -58,7 +58,17 @@ defmodule AshCubDB.DataLayer do
|
|||
def can?(_, :filter), do: true
|
||||
def can?(_, {:filter_expr, _}), 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
|
||||
@impl true
|
||||
|
@ -266,7 +276,7 @@ defmodule AshCubDB.DataLayer do
|
|||
|> Runtime.filter_matches(records, query.filter, parent: parent)
|
||||
end
|
||||
|
||||
defp runtime_sort(records, query) do
|
||||
defp runtime_sort(records, query) when is_list(records) do
|
||||
records =
|
||||
records
|
||||
|> Sort.runtime_sort(query.distinct_sort || query.sort, api: query.api)
|
||||
|
@ -278,6 +288,8 @@ defmodule AshCubDB.DataLayer do
|
|||
{:ok, records}
|
||||
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, limit), do: Enum.take(records, limit)
|
||||
end
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -1,7 +1,7 @@
|
|||
defmodule AshCubDB.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
@version "0.3.0"
|
||||
@version "0.3.1"
|
||||
|
||||
@moduledoc """
|
||||
A CubDB data layer for `Ash` resources.
|
||||
|
|
|
@ -127,6 +127,19 @@ defmodule AshCubDB.DataLayerTest do
|
|||
|
||||
assert expected.id == actual.id
|
||||
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
|
||||
|
||||
describe "update" do
|
||||
|
|
Loading…
Reference in a new issue