cloedu87
Hi there,
I’m working with ash now a couple of weeks and I’m quite a big fan
but now I’m struggling with a - so it seems - basic usecase.
I’m using the ash framework to manage my resources in the database (postgres).
I would like to store structs which are from a foreign library, namely instances of Ash.Query, to the datasbase. like:
attributes do
attribute :query, Ash.Query
...
end
Of course using Ash.Query directly as type is not possible. My first intention was to solve this with a custom Ash.Type and use…
@impl true
def storage_type, do: :map
…to tell the data layer I would like to store it as a :map on the data layer. but this did not work.
My question is: how can I define attributes on my ash resources, which are able to store structs of foreign libraries (structs which are NOT part of my code/project) and if it is only possible over custom Ash.Type’s, how can I serialize those structs properly, so I can write and read them like regular attributes?
Thanks for any hints ![]()
Claudio
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
Well, I would very much advise against storing that kind of data in your database to be honest. But, if you must, use the
:termtype, which usesbinary_to_termandterm_to_binaryto encode/decode to binary storage.Why do you want to store an Ash.Query in a database?
cloedu87
Thx for the reply!
I got a data export feature. for each export (which runs async as oban jobs) I have to define specific filter criteria, so I can select data dynamically according to various situations.
to run, re-run and schedule those exports for later execution I have to - somehow - persist those filters/query criterias.
such a query/criteria basically looks like:
I honestly couldn’t find another solution to properly serialize those filters to re-use them later…
Best, C.
zachdaniel
I would suggest using the
mapsyntax that Ash filters support. For example:Ash.Query.filter(%{id: %{eq: ^id}})Then you can persist the map
cloedu87
This would be awesome…
but how is it with relations?
like I do with
I have to do queries over my related resources, can I dynamically load relations, according to a query?
zachdaniel
Loading related data and referencing related data in filters is actually unrelated. You don’t need to load something to reference it. In the case of the map syntax, it would be
%{some_stuff: %{id: %{eq: id}}}cloedu87
yes, right.. will do it this way, thank you very much
and thx for the awesome framework. it’s simply great