Better support for inline data class
See original GitHub issueI like that you can use the inline data class for things like ids. However, the ceremony around it with custom ColumnAdapters and Adapters feels a bit too much.
I’ve got 3 tables. Player
and Game
both for which I have custom Id classes and then PlayerGame
to resolve the m:n
relationship.
In order to satisfy sqldelight I need to hook it up with custom converters:
private val columnAdapterGameId = object : ColumnAdapter<GameId, Long> {
override fun decode(databaseValue: Long) = GameId(databaseValue)
override fun encode(value: GameId) = value.value
}
private val columnAdapterPlayerId = object : ColumnAdapter<PlayerId, Long> {
override fun decode(databaseValue: Long) = PlayerId(databaseValue)
override fun encode(value: PlayerId) = value.value
}
private val queryWrapper = QueryWrapper(sqliteDriver, Game.Adapter(columnAdapterGameId), Player.Adapter(columnAdapterPlayerId), PlayerGame.Adapter(columnAdapterPlayerId, columnAdapterGameId))
Given that sqldelight can look at the Kotlin code would it be possible to also autogenerate the ColumnAdapter
for inline data classes? That way I can reference them directly and don’t need to create the Adapters manually. If it can do that, we could even provide default parameters for the QueryWrapper
class parameters so that I can end up using:
private val queryWrapper = QueryWrapper(sqliteDriver)
While still having the possibility to specify converters as I please.
Issue Analytics
- State:
- Created 5 years ago
- Comments:33 (15 by maintainers)
Top GitHub Comments
I can confirm that using Kotlin 1.4 fixes this issue (independently of SQLDelight targeting 1.4).
The fix is in the EAP version. Please confirm that you are testing 1.4 M2 and not earlier @vincent-paing 🙏🏽