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

Querying against Enums is difficult #11

Open
JvmName opened this issue Jan 23, 2025 · 1 comment
Open

Querying against Enums is difficult #11

JvmName opened this issue Jan 23, 2025 · 1 comment

Comments

@JvmName
Copy link
Member

JvmName commented Jan 23, 2025

Because KotlinX Serialization handles marshalling/unmarshalling enums, if you don't provide a @SerialName, the default serializer will use enum.ordinal.

This is difficult: you can't query against the ordinal Int, since your entity presumably defines it as the Enum, so your Where will look like:

MyEntity::direction eq 2 //💥 type error

if you try to do MyEntity::direction eq Direction.North.name, it'll compile but Sqkon won't return any data...unless you use SerialName("North") as a workaround

@tadfisher
Copy link

I think value binding needs to be serialization-aware, e.g. bindValue should be running the value through KeyValueStorage.serializer and binding a string instead of the raw value. So Eq<MyEntity, Direction> should also carry typeof<Direction>(), and KeyValueStorage should use the serialized value when preparing the SQL statement.

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

2 participants