In Introduction to Multiplatform Persistence with SQLDelight it was mentioned that we still needed way to “manage observing of data updates (some interesting work being done on extension that supports Kotlin Coroutines Flow)”. Well, not long after that SQLDelight 1.1.4 was released with the aforementioned Flow support and this post gives short overview of exploration done to start using it.
SQLDelight 1.1.4 is out! Highlights:
— Alec Strong (@Strongolopolis) July 11, 2019
- Kotlin/Native 1.3.40 support
- Kotlin Flow API
- Me figuring out how gradle plugin development works for the hundredth timehttps://t.co/3AZxfQLOta
Previously we had code like following in GalwayBusRepository
(and continue to have so to support usage on iOS - more on that later). This would of course have only provided snapshot of what was in db at that time.
With Flow support we can now add following (note asFlow()
usage).
This can then be invoked like following (using Flow’s collect()
function) and code in lambda will get called each time db is updated.
Regarding Kotlin Native support it looks like more work is still needed to support this (getting InvalidMutabilityException
right now when I try to use this on iOS). See following for example - https://github.com/square/sqldelight/issues/1394 (I’ll post updates here when that situation changes)
Above code is available in the GalwayBus github repo.
Featured in Kotlin Weekly Issue #156
Related tweet
Exploring SQLDelight Flow support https://t.co/cO4nBNjvR3
— John O'Reilly (@joreilly) July 21, 2019
(very!) short follow on post describing update to start using new Kotlin Flow support https://t.co/CLK2DfhdJF