circuithub / rel8

Hey! Hey! Can u rel8?
https://rel8.readthedocs.io
Other
150 stars 38 forks source link

Allow `exists` to be used within expressions #301

Closed gkaracha closed 6 months ago

gkaracha commented 6 months ago

Hello! Is there a way to encode in Rel8 the following idiom?

SELECT ...
FROM table_name 
WHERE
  (condition1
  OR EXISTS (<some query here>)   -- this
  OR ...) 

More specifically, is there a way to use EXISTS in an Expr context? Currently exists seems to only work within Query, which makes it impossible to use it within a where_ clause

exists :: Query a -> Query (Expr Bool)

Is there a workaround for this at the moment? If not, are there any plans to implement this feature in the future?

For a little bit of context: in the project I'm currently working on we are trying to migrate from Hasql to Rel8 and a part of that is the conversion of filtering. The frontend sends potentially complex filters to the backend, which are then converted to an SQL expression that becomes part of a where_ clause. Hence the need to use exists within the Expr context.

Thanks for all the work you've put into this wonderful library!