moissela
moissela
AEAsh Elixir
Created by moissela on 8/22/2023 in #support
Suggestion broken with latest ElixirSense
Hi @Zach Daniel, I've found a bug using Spark autocomplete suggestion in vscode with latest ElixirSense release. Issue here https://github.com/ash-project/spark/issues/54 and tried to fix that with a PR here https://github.com/ash-project/spark/pull/55
2 replies
AEAsh Elixir
Created by moissela on 8/9/2023 in #showcase
AshUUID: extension for using UUID v4 and v7, with encoding and prefixing support
Hi there, already released a new Ash extension for enhancing Ash UUID fields support. AshUUID allows usage for UUID v4 and the new v7 draft (official paper: https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-04.html#name-uuid-version-7, more about: https://blog.devgenius.io/analyzing-new-unique-identifier-formats-uuidv6-uuidv7-and-uuidv8-d6cc5cd7391a). You can use public shortened version of UUIDs through base62 encoding while keeping them stored as native raw uuid column on Postgres (with all the indexing / querying benefits). AshUUID allows using public shortened version with prefix at the beginning (configurable, default to resource name) like Stripe does for better APIs (more about: https://dev.to/stripe/designing-apis-for-humans-object-ids-3o5a). New AshPostgres feature (https://github.com/ash-project/ash_postgres/pull/162) allows Ash extensions to easily ship Postgres functions extensions through the new AshPostgres.CustomExtension behaviour (example: https://github.com/zoonect-oss/ash_uuid/blob/main/lib/ash_uuid/postgres_extension.ex). With AshPostgres v1.3.41 release, AshUUID provides Postgres-side UUIDv7 generation (through uuid_generate_v7 sql function) for better db integrity. AshUUID adoption: - add {:ash_uuid, "~> 0.2"} to your mix.exs project deps; - add AshUUID.PostgresExtension to your app Repo's installed_extensions and set AshUUID config migration_default?: true if Postgres-side UUIDs generation is needed; - use the extension in your resources use Ash.Resource, data_layer: AshPostgres.DataLayer, extensions: [AshUUID] - simply use that for your fields uuid_attribute :id v0.2.2 is released on Hex: feel free to open issues/PRs or to reply to this thread, feedbacks are welcome 🙂 Happy for my first contribution to the Ash community 💪🏼 https://github.com/zoonect-oss/ash_uuid
129 replies
AEAsh Elixir
Created by moissela on 7/28/2023 in #support
Prefixed base62 UUIDv7 primary key implementation with Ash
Hi all, I'm trying to implement a UUIDv7 based primary key for all our Ash resources (and relationships), storing that as UUID type column on PostgreSQL and presenting that outside as a prefixed base62 string (0188aadc-f449-7818-8862-5eff12733f64 will be shown as acct_02tRrww6GFm4urcMhyQpAS), like what is described here for Ecto (https://danschultzer.com/posts/prefixed-base62-uuidv7-object-ids-with-ecto). I'll be happy to contribute with the result of this as a code sample or better as an elixir package as soon as I get it all working properly. What I'd like to know, maybe from @Zach Daniel, is what is the better way with Ash to add a Resource's DSL helper like uuid_primary_key? With older version of Ash and Spark I've successfully patched the Resource's DSL, but with newer version it seems that here https://github.com/ash-project/ash/blob/main/lib/ash/resource/dsl.ex#L127 on Ash side is missing the patchable?: true option that's is defined here https://github.com/ash-project/spark/blob/f997db91f74e772cd19656148092f439743f9cd8/lib/spark/dsl/section.ex#L42 on Spark side. It seems a philosophical decision on the framework side to explicitly disallow DSL patching, so I'm wondering what is the correct way to do it. It would be great to be able to contribute to ash via an external package that will add to the Resource's DSL a simple helper like prefix_uuidv7_primary_key. Another question is how to know in the Ash type module definition the Ash Resource in which it is included as an attribute, in order to generate or obtain the right prefix (maybe with Resource metadata or through a new DSL specific section). Unfortunately I think this is not possible right now so I'm trying to get around the problem by using the constraints like constraints: [prefix: "acct"] because that it's the only flexible parameter I found on the Ash types. And of course any advice or tip is welcome 😅
25 replies
AEAsh Elixir
Created by moissela on 4/19/2023 in #support
Resource's DSL "metric" actions
Hi @Zach Daniel, related to yesterday's question (https://discord.com/channels/711271361523351632/1097912088296443904) I got a new hint: we're trying a full-spread ash adoption on our internal project and we're trying to use only resource's code-interfaces everywhere, but for yesterday count/1 I've to call api module directly. What about the idea of a new kind of action supported by ash resource's DSL for defining resource's metrics methods in a declarative way? For example on a User resource we can declare a simple metric :daily_subscribers action applying some logic and filters that returns a count of that metric. Going forward we could think about a more widely metric :subscribers_growth action accepting a period argument that let us select a specific time window for that metric. All this actions could then be declared within the resources's code_interface. I think this new kind of actions could be an useful feature on all ash extension (graphql, json, ...) 🙂
2 replies
AEAsh Elixir
Created by moissela on 4/18/2023 in #support
How to make simple select count with Ash
Hi, maybe a noob question here 😅 but I'm wondering which is the right way of making a simple select count of my Users on a Postgres-based app. I could do that with MyApi.count(MyResource) but on the docs that method belongs to the ambigous Ash.Filter.ShadowApi module. I can't find anything else on the docs 🤷🏼‍♂️ For context, I'm trying to make some filtered and unfiltered counts on my direct resource and not an aggregate count on related resources.
11 replies
AEAsh Elixir
Created by moissela on 3/20/2023 in #support
AshPhoenix Form use for `many_to_many` relationships through `append_and_remove` management
Hi all, and thanks for this amazing project! Today I'm trying to figure out how to use AshPhoenix.Form with field of type {:array, :uuid}, for example in the context of managing a many_to_many relationships through append_and_remove, in extension of your example here https://hexdocs.pm/ash/2.6.18/managing-relationships.html. For example, I have this resources with the desired result of allowing the user to select a list of tags from a multiple select: defmodule Post do use Ash.Resource, data_layer: AshPostgres.DataLayer postgres do table "posts" repo Repo end attributes do uuid_primary_key(:id) attribute(:title, :string) attribute(:content, :string) end relationships do many_to_many :tags, Tag do through PostTag source_attribute_on_join_resource :post_id destination_attribute_on_join_resource :tag_id end end actions do update :set_tags do argument :tags, {:array, :uuid} change manage_relationship(:tags, type: :append_and_remove) end end defmodule Tag do use Ash.Resource, data_layer: AshPostgres.DataLayer postgres do table "tags" repo Repo end attributes do uuid_primary_key(:id) attribute(:name, :string) end relationships do many_to_many :posts, Post do through PostTag source_attribute_on_join_resource :tag_id destination_attribute_on_join_resource :post_id end end end defmodule PostTag do use Ash.Resource, data_layer: AshPostgres.DataLayer postgres do table "post_tags" repo Repo end attributes do uuid_primary_key(:id) end relationships do belongs_to :post, Post, allow_nil?: false belongs_to :tag, Tag, allow_nil?: false, attribute_writable?: true end end With this in place, how can I use AshPhoenix.Form auto-form and/or inputs_for for generating the post[tags][] fields in a clean way?
17 replies