sezaru
How to run a second query inside a read action?
Hey, I have a read query that uses pg_trgm and I want to set word_similarity_threshold before running it.
I tried something like this:
read :by_entity do
argument :entity_full_name, :string, allow_nil?: false
prepare fn query, context ->
Ash.Query.before_action(query, fn query ->
Pacman.Repo.query!("set pg_trgm.word_similarity_threshold = 0.99") |> dbg()
query
end)
end
filter expr(fragment("(? %> ?)", first_grantee_full_name, ^arg(:entity_full_name))
and not is_nil(recording_date || instrument_date)
and (recording_date || instrument_date) >= ago(2, :year)
and not deleted?)
prepare build(sort: [:recording_date])
end
But this doesn’t seem to work, I believe because there is no commit query encapsulating both queries inside the same transaction.
What would be the best way to achieve this with Ash?
Marked As Solved
sezaru
Oh, I just found out that I can pass transaction? true to the read action and that will make the read action be encapsulated inside a transaction making my preparation work as expected.
Since that is fixed, just another question, would Pacman.Repo.query!("set pg_trgm.word_similarity_threshold = 0.99") be the best way to run such a query or is there a better way to do it with Ash?
0
Also Liked
zachdaniel
Creator of Ash
Popular in Questions
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Other popular topics
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









