Using config values in filter expressions

I have a fairly simple read action, like so:
read :get_by_id do
get? true

argument :id, :uuid, allow_nil?: false

filter expr(expires_at > now())
filter expr(attempts < 3)
end
read :get_by_id do
get? true

argument :id, :uuid, allow_nil?: false

filter expr(expires_at > now())
filter expr(attempts < 3)
end
The max attempts is set in the config and I would like to use that rather than a hardcoded count. I couldn't figure out a way to get it in there nicely as-is. Is the best way to do it using a prepare function?
5 Replies
ZachDaniel
ZachDaniel4mo ago
yes, a preparation is the best way 👍 I guess you could use lazy though now that I think of it
Steve
SteveOP4mo ago
What is lazy exactly?
ZachDaniel
ZachDaniel4mo ago
filter expr(lazy({Application, :get_env, [:my_app, :config_name]}))
filter expr(lazy({Application, :get_env, [:my_app, :config_name]}))
It takes an MFA and evaluates it when the expression is evaluated So either the lazy/1 expression or a preparation
Steve
SteveOP4mo ago
I think I'd prefer to do a preparation.
ZachDaniel
ZachDaniel4mo ago
Same 🙂

Did you find this page helpful?