Compare commits

...

3 commits

Author SHA1 Message Date
8b2f2ade4c chore: release version v0.4.1
All checks were successful
continuous-integration/drone/push Build is passing
2023-10-02 03:19:02 +00:00
b53fca0be3
docs: update README.md.
All checks were successful
continuous-integration/drone/push Build is passing
2023-10-02 16:15:38 +13:00
34dac0337a
fix: correctly enable filtering and sorting. 2023-10-02 16:15:06 +13:00
7 changed files with 89 additions and 14 deletions

View file

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

View file

@ -19,14 +19,16 @@ AshCubDb is still a work in progress. Feel free to give it a go.
| Read (by primary key) | ✅ |
| Read (filters) | ✅ |
| Read (sort) | ✅ |
| Read (calculations) | ❌ |
| Read (distinct sort) | ✅ |
| Read (calculations) | ✅ |
| Read (aggregates) | ❌ |
| Update | ✅ |
| Destroy | ✅ |
| Transactions | ❌ |
## Github Mirror
This repository is mirrored [on Github](https://github.com/jimsynz/smokestack)
This repository is mirrored [on Github](https://github.com/jimsynz/ash_cubdb)
from it's primary location [on my Forejo instance](https://code.harton.nz/james/ash_cubdb).
Feel free to raise issues and open PRs on Github.
@ -38,7 +40,7 @@ by adding `ash_cubdb` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:ash_cubdb, "~> 0.4.0"}
{:ash_cubdb, "~> 0.4.1"}
]
end
```

View file

@ -57,10 +57,15 @@ defmodule AshCubDB.DataLayer do
def can?(resource, :read), do: Dir.readable?(resource)
def can?(_, :multitenancy), do: true
def can?(_, :filter), do: true
def can?(_, :limit), do: true
def can?(_, :offset), do: true
def can?(_, :distinct), do: true
def can?(_, :distinct_sort), do: true
def can?(_, {:filter_expr, _}), do: true
def can?(_, :boolean_filter), do: true
def can?(_, :sort), do: true
def can?(_, {:sort, _}), do: true
def can?(_, :nested_expressions), do: true
def can?(resource, capability) do
if Application.get_env(:ash_cubdb, :debug_data_layer_capabilities?, false) do

View file

@ -1,7 +1,7 @@
defmodule AshCubDB.MixProject do
use Mix.Project
@version "0.4.0"
@version "0.4.1"
@moduledoc """
A CubDB data layer for `Ash` resources.
@ -23,7 +23,7 @@ defmodule AshCubDB.MixProject do
aliases: aliases(),
dialyzer: [plt_add_apps: [:faker, :smokestack]],
docs: [
main: "AshCubDB",
main: "readme",
extra_section: "Guides",
formatters: ["html"],
filter_modules: ~r/^Elixir.AshCubDB/,

View file

@ -1,4 +1,5 @@
defmodule AshCubDB.DataLayerTest do
@moduledoc false
use ExUnit.Case, async: true
alias Ash.{Error.Query.NotFound, Query}
alias AshCubDB.Info
@ -140,6 +141,51 @@ defmodule AshCubDB.DataLayerTest do
assert Enum.map(sorted, &to_string(&1.name)) == ["Mallory", "Bob", "Alice"]
end
test "limit" do
insert!(Author, count: 3)
assert [_] =
Author
|> Query.limit(1)
|> Api.read!()
end
test "offset" do
insert(Author, count: 3)
assert [_, _] =
Author
|> Query.offset(1)
|> Api.read!()
end
test "distinct" do
author = insert!(Author)
insert!(Author, count: 3, attrs: %{name: author.name})
assert [selected] =
Author
|> Query.distinct(:name)
|> Api.read!()
assert selected.name == author.name
end
test "distinct sort" do
post = insert!(Post, attrs: %{body: "Alice is cool"})
insert!(Post, attrs: %{title: post.title, body: "Bob is cool"})
insert!(Post, attrs: %{title: post.title, body: "Mallory is cool"})
assert [selected] =
Post
|> Query.distinct(:title)
|> Query.distinct_sort(body: :desc)
|> Api.read!()
assert selected.title == post.title
assert selected.body == "Mallory is cool"
end
end
describe "update" do
@ -166,6 +212,15 @@ defmodule AshCubDB.DataLayerTest do
end
end
describe "calculations" do
test "can be loaded" do
post = insert!(Post)
{:ok, post} = Post.get(post.id, load: :all_text)
assert post.all_text == post.title <> post.body
end
end
defp dump(resource) do
resource
|> via()

View file

@ -7,28 +7,28 @@ defmodule Support.Author do
end
multitenancy do
strategy(:context)
global?(true)
strategy :context
global? true
end
attributes do
uuid_primary_key(:id)
uuid_primary_key :id
attribute(:name, :ci_string)
attribute :name, :ci_string
end
relationships do
has_many(:posts, Support.Post)
has_many :posts, Support.Post
end
actions do
defaults(~w[create read]a)
defaults ~w[create read]a
end
code_interface do
define_for(Support.Api)
define_for Support.Api
define(:create)
define(:read)
define :create
define :read
end
end

View file

@ -19,6 +19,10 @@ defmodule Support.Post do
defaults ~w[create read update destroy]a
end
calculations do
calculate :all_text, :string, expr(title <> body)
end
relationships do
belongs_to :author, Support.Author
end