question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better support for inline data class

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:33 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
leandrofavarincommented, Aug 21, 2020

I can confirm that using Kotlin 1.4 fixes this issue (independently of SQLDelight targeting 1.4).

0reactions
efemoneycommented, Oct 20, 2020

The fix is in the EAP version. Please confirm that you are testing 1.4 M2 and not earlier @vincent-paing 🙏🏽

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inline classes - Kotlin
To solve such issues, Kotlin introduces a special kind of class called an inline class. Inline classes are a subset of value-based classes....
Read more >
Kotlin 1.5 Inline Classes — Improve Code Maintainability At ...
Because an inline class represents one specific type, it can only take one variable at a time. So if you want to wrap...
Read more >
What's The Different between data class and inline class in ...
Inline class is all about wrapping a type in a new class. It is more like type aliases but it also gives us...
Read more >
Kotlin Inline Classes - How they work and when you should ...
We saw that inline classes have a huge advantage: In the best case, they reduce runtime overhead drastically since additional heap allocations ...
Read more >
My top 4 use cases for Kotlin inline classes - ProAndroidDev
You can't wrap multiple values in one inline class. Also, you cannot have properties with backing fields and property delegation isn't supported. However, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found