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

Unable to filter on an optional enum value #307

Open
mattdavpir opened this issue Aug 14, 2023 · 1 comment
Open

Unable to filter on an optional enum value #307

mattdavpir opened this issue Aug 14, 2023 · 1 comment

Comments

@mattdavpir
Copy link

Version: 4.6.0.1
Module: quill-jdbc-zio
Database: Postgres

Expected behavior

Filtering on an optional enum value should generate a query.

Actual behavior

There's a compilation error of "The Co-Product element was not a Case Class or Value Type. Value-level Co-Products are not supported. Please write a decoder for it's parent-type".

Steps to reproduce the behavior

https://scastie.scala-lang.org/j5t5LHW6Rnef3DP2cgaBew

Doing myTableQuery.filter(_.myTableType == lift(filter)) will compile, but using an optional filter and doing myTableQuery.filter(mt => lift(maybeFilter).forall(mt.myTableType == _)) will not. For an optional string query it would generate something like Quill Query: SELECT mt.id, mt.name, mt.my_table_type FROM my_table mt WHERE ? IS NULL OR mt.name = ?, so I think it should be doing something similar for an enum.

Workaround

@getquill/maintainers

@mattdavpir
Copy link
Author

mattdavpir commented Aug 15, 2023

Actually I think as a workaround I can change that to be something more like the SQL generated by the forall statements, e.g. rather than myTableQuery.filter(mt => lift(maybeFilter).forall(mt.myTableType == _)) I can do something like myTableQuery.filter(mt => lift(maybeFilter.orNull) == null || mt.myTableType == lift(maybeFilter.orNull)).

edit - Although I also need to handle the null case in the encoder if I do this, I think.

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

No branches or pull requests

1 participant