Custom query run in action
I'm wondering how to run a regular query (SELECT ...) in an action for example using
Repo.query!
š¤ my attempts fail. Seems I can't use the Repo module in an action š¬Solution:Jump to solution
I literally showed you how to do it.
```elixir
action :activity_thismonth, :map do
run fn input, ->
"""...
15 Replies
In what context? a manual read? A generic action?
How did your attempts fail?
You can definitely use the repo module in an action š
hmm, generic action, okay
for example if I have a resource with
and an action
I'm getting on
mix compile
š¤Your repo is not started
is the repo in your application supervision tree?
it is
tried it on another project, same error. You're saying the above should work? Can you try it please š I also thought this should work but :/
omg wait nvm š©
lol
Two things:
1. generally on you to get a reproduction running š
2. no it doesn't work
Your example was trying to use the repo at compile time
So it wasn't started
make sure to read the generic actions guide š
alright :thinkies:
wdym by
You can definitely use the repo module in an actionthen? why is it being used at compile time? I thought it's used when called... I'm guessing I should do this sort of thing outside of an resource then, just a regular function call. š¤
š¤
What exactly are you trying to do
To describe what happens when a generic action is called, you provide a function to the
run
option
like the code example I just showed you
that is how you define a generic action.
What you tried to do is the equivalent of attempting to use the repo module at compile time, while defining a generic actionI wanted to have an action that returns something custom related to that resource table, I'm doing some custom counting. I moved it to a function inside the resource and that works.
there are no special rules about how they workI thought it should work but I guess not everything belongs in an action š thank you for helping š to quote Socrates: all I know is that I know nothing š
@ken-kost you aren't understanding me lol
It absolutely does work in a generic action
you just typed your generic action wrong, thats all
Solution
I literally showed you how to do it.
omg
šµ
Probably me saying
2. no it doesn't workthrew your for a loop, my bad š
yeah I thought this doesn't work:
man... I should rest
okay. at least I thought right. just missed the syntax
everything belongs in an action
