Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with supporting full-body query functions #4

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hauleth
Copy link
Owner

@hauleth hauleth commented Jun 15, 2021

For now cond statements are supported, but it can uncleanly fail if there is unsupported construct in the query function body.

Up to discussion:

  • maybe support some of the cases (with the constants as the match patters) as PostgreSQL supports such construct
  • if and unless, but it will make them work slightly different from the Elixir one, as PostgreSQL is statically typed, so there is no way to simulate it for non-bool condition
  • variables assignment? I am not even sure how that could work at all, but if someone have any idea, then I will be open

Things needed to be done before merging:

  • Tests, extensive test suite
  • Clean handling of invalid function body

Goal of this PR is to add support for more complex query functions, for example support conditionals like:

defq clamp(val) do
  cond do
    val < 0.0 -> 0.0
    val > 1.0 -> 1.0
    true -> true
  end
end

Which then can be used in the query just as you would expect:

from entry in "entries",
  select: %{clamped: clamp(entry.value)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant