I'm using SQLDelight. Can I use enum constant in t...
# squarelibraries
p
I'm using SQLDelight. Can I use enum constant in the query, so it'll be converted with the adapter?
Copy code
CREATE TABLE SomeTable(
  enumColumn TEXT AS EnumClass
);


update:
UPDATE SomeTable
SET enumColumn = EnumClass.EnumItem;
I can use argument instead of
EnumClass.EnumItem
, but my query only makes sense with single enum constant.
d
I just ran into this situation as well and stumbled upon this message via search. It's possible to achieve this result, but the workaround is a little ugly:
Copy code
enumColumn = '${SomeTableAdapter.enumColumnAdapter.encode(fully.qualified.package.EnumClass.EnumItem)}'
The generated SomeTableQueries.kt code will wrap the update SQL in a multiline string literal. That means we can take advantage of string interpolation inside the generated code's update query string. By going through the column adapter to write the string value of the enum we can avoid hard-coding as much as possible.
192 Views