https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
room
  • b

    Brandon Trautmann

    04/11/2019, 1:34 AM
    Anyone aware of reactive coroutine return types from db interactions being on the roadmap for Room? I see that for RxJava we get
    Flowable
    ,
    Maybe
    , etc. but I don't something like that for coroutines in
    2.1.0
    z
    s
    • 3
    • 5
  • p

    Parthiv Mistri

    01/17/2020, 7:12 AM
    Hello,
    @Entity
    @TypeConverters(TeamModelTypeConverters::class)
    data class User(
        @PrimaryKey var id: Int? = null,
        var team: List<TeamModel>? = null,
        var organization_l1: OrganizationModel? = null,
        var organization_l2: OrganizationModel? = null,
    )
    As you can see I have
    OrganizationModel
    in 2 place. I can not use
    @Embedded
    As it will give me error regarding same field while creating a table. Can Anyone help me on this? Thanks
    m
    • 2
    • 1
  • k

    kyleg

    01/26/2020, 10:07 PM
    Can I not have non-abstract methods in my DAO interface? I have a DAO function that takes an object, but since you can’t destructure the object directly, I manually unwrap it and call a private method:
    data class Foo(val x: Int, val y: String)
    
    @Dao interface MyDao {
      @Query("...")
      private suspend fun _getData(x: Int, y: String): Int
      suspend fun getData(foo: Foo) = _getData(foo.x, foo.y)
    }
    But I get an error when trying to build my project:
    error: MyDao_Impl is not abstract and does not override abstract method getData(......
    How do I resolve this without forcing a non-DAO function to do the unwrapping?
    m
    • 2
    • 2
  • r

    Roar Gronmo

    01/30/2020, 8:18 PM
    "Nullsafety" of Kotlin Room "Single element" Query Given Room Dao Query:
    @Query("SELECT * FROM stations WHERE stationId = :stationId LIMIT 1")
        fun getStation(stationId: String): Station
    What will happen if ":stationID" is not found, how is that element returned, null ? Above expression is set as "nullsafe" (No warning telling that I should return
    Station?
    instead,) and handle the null check in my code. AS should give a Lint Error/Warning here to tell that the result may return null. My app fails at this point when handling a null (that obviously shouldn't be null...) RG
    k
    • 2
    • 12
  • p

    Pablo

    08/18/2020, 2:20 PM
    Hello I'm trying to create a simple room example app but I'm facing some issues when trying to do a query, can you please take a look on this? [1], I've read about Embeded and Relation but I'm afraid because I'm using a
    *.db
    script to initialise the database and I don't know if it will break something. [1] : https://stackoverflow.com/questions/63382855/how-to-add-embedded-and-relation-to-room-database
    r
    • 2
    • 1
  • j

    Joan Colmenero

    08/20/2020, 1:30 PM
    Anyone of you guys have used Pre-packaged room before? I'm using this new API method
    createFromAsset(file path of db)
    but looks like is not updating the db when inserting or deleting, whell for the first time it does populate everything that I have, then when I update the data and check the DB Browser for SQLite is not being reflected and when I close the app and open it again it keeps the same data as the start. Any idea?
    r
    • 2
    • 1
  • a

    Andy Gibel

    09/09/2020, 5:00 PM
    Hi all - I'd like to do something that seems like it should be simple but... is not 😕. I have a Dao for a model with nullable fields. That model is created locally and then is subsequently updated via a model coming from the network. The model has some derived foreign keys and therefore those columns are not present coming from the API. I basically just want to update any fields ONLY when the update is nonNull.
    • 1
    • 2
  • p

    pollux-

    09/14/2020, 11:40 PM
    I have a pre packaged SQL database. Which has couple of Boolean fields. When I import that DB using Room it's throwing an error staying Pre packaged database has invalid schema I'm guessing problem is that, DB has boolen field type but Room table we can't have Boolean its being used and Integer field. How can I solve this?? Thanks
    m
    • 2
    • 5
  • m

    Marcin Środa

    10/01/2020, 12:47 PM
    Hi! Can anybody tell me how to deal with
    Flow
    in Room? Easy queries works fine, but what if I wan’t to use more extended like:
    @Query("SELECT id, (SELECT COUNT(id) FROM `message` WHERE channelId = channel.id and timestamp > channel.custom_readAt) as `unreadCount` FROM `channel`")
    fun getAll(): Flow<List<UnreadMessageData>>
    the new value is not emited. But in DatabaseInspector with ‘live update’ enabled it works fine. Any ideas?
    • 1
    • 3
  • s

    Saul Wiggin

    10/26/2020, 11:42 AM
    Trying to add API to room database. Not sure if I am creating the data classes correctly. Getting this error
    public final class DatabaseBitcoin {
    ^
    Tried the following constructors but they failed to match:
    DatabaseBitcoin(int,com.example.paywithbitcoin.database.Time,java.lang.String,java.lang.String,java.util.List<com.example.paywithbitcoin.database.Currency>) -> [param:id -> matched field:id, param:time -> matched field:unmatched, param:disclaimer -> matched field:disclaimer, param:chartname -> matched field:chartname, param:bpi -> matched field:unmatched]/Users/drsilaswiggin/dev/kotlin/PayWithBitcoin/app/build/tmp/kapt3/stubs/debug/com/example/paywithbitcoin/database/DatabaseBitcoin.java:7: error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
    g
    • 2
    • 1
  • m

    Mohsen

    11/15/2020, 6:05 PM
    const val FORECAST_ID = 0
    
    @Entity(tableName = "forecast")
    data class ForecastEntry(
        @Ignore
        @Embedded(prefix = "current_")
        val current: Current = Current(),
        @Ignore
        @Embedded(prefix = "daily_")
        val daily: List<Daily> = listOf(),
        @Ignore
        @Embedded(prefix = "hourly_")
        val hourly: List<Hourly> = listOf(),
        @Ignore
        val lat: Double = 0.0,
        @Ignore
        val lon: Double = 0.0,
        @Ignore
        val timezone: String = "",
        @Ignore
        @SerializedName("timezone_offset")
        val timezoneOffset: Int = 0
    ) {
        @PrimaryKey(autoGenerate = false)
        var id: Int = FORECAST_ID
    
        constructor() : this(Current(), listOf(), listOf())
    }
    could anyone help me please?
    h
    • 2
    • 6
  • r

    Ray

    12/07/2020, 4:17 PM
    message has been deleted
    🇳🇴 1
    k
    • 2
    • 2
  • j

    Jorge R

    12/15/2020, 10:44 PM
    Hi all! [SOLVED] We are having a problem with Room database that returns a flow (that is converted to LiveData in ViewModel layer) not notifying DB changes. LiveData Observer-query is being fired from an APP process, but database insertions are fired by another process. Is this an expected behaviour? We can see data in the query table, but for some reason, LiveData update it is not being triggered. If we manually add data from the APP process, LiveData gets triggered. Any idea? Thank you!
    m
    • 2
    • 10
  • m

    Mantas Varnagiris

    12/18/2020, 7:36 PM
    I'm trying to use
    Room
    with
    Paging 3
    . I'll explain my setup first so the problem is a bit clearer •
    database (android module)
    has
    Room
    . It has a
    Dao
    with
    fun getItems(): PagingSource<Int, ItemEntity>
    •
    ItemEntity
    is internal only to
    database
    module - I don't want to use it in domain. It is converted to
    Item
    •
    core (kotlin module)
    has
    Paging 3
    . It wants to do paging using
    PagingSource<Int, Item>
    (not
    ItemEntity
    as it has no knowledge of it) •
    database
    module implements interface that gives
    PagingSource<Int, Item>
    Now my problem is that I cannot convert from
    PagingSource<Int, ItemEntity>
    to
    PagingSource<Int, Item>
    . At least I could not find a way to do it. I don't want to expose
    ItemEntity
    but I want to do paging with converted model
    Item
    . How can I do that?e
    j
    d
    • 3
    • 14
  • b

    bohsen

    01/07/2021, 10:32 AM
    In order to support synchronization of time using NTP for time sensitive data, I've added a
    Volatile
    property to our
    RoomDatabase
    from where all update operations can request a "timestamp". But I was wondering if this is threadsafe in regards to using Room with suspending functions and transactions? Also not quite sure it actually has to be marked as
    Volatile
    as every access should produce a new
    java.time.Clock
    . Code follows in thread...
    • 1
    • 1
  • l

    lewis

    02/22/2021, 10:58 AM
    I started using KSP with Room late last week, when my build reaches
    compileReleaseJavaWithJavac
    it inconsistently (I've not been able to find the trigger to reproduce it yet) fails as the generated Impl class for my Dao contains a method that no longer exists on the Dao (removed many builds ago). I thought this may be due to a build cache issue, but disabling caching does not resolve it, clean build also currently consistent produces the same outcome. Is there anything I can dig/capture to help debug?
    y
    • 2
    • 5
  • a

    André Thiele

    03/26/2021, 8:16 PM
    Is it possible to do something like this? (Using a Relation as another Relation)
    y
    • 2
    • 3
  • k

    KingKongCoder

    04/07/2021, 3:57 PM
    How to safely migrate a entity part of app modules room database to a feature module room database? i am encountering this as i am modularzing code base and moving one of the entities part of app module to a feature module having its own Room database
    y
    m
    • 3
    • 5
  • m

    Mini

    06/14/2021, 3:28 PM
    I am trying to add multiple @DeleteColumn to an AutoMigrationsSpec, however I get this error
    Repeatable annotations with non-SOURCE retention are not yet supported
    Im confused, is multiple @DeleteColum not supported? It`s annotated with @Repeatable
    y
    • 2
    • 6
  • a

    André Thiele

    07/26/2021, 4:42 PM
    I get this error every now and then and dont know how to resolve it in production. The schema is different, because the columns are in a different order and causes my app to crash. See the code:
    • 1
    • 1
  • s

    Shawn Tucker

    07/27/2021, 11:22 AM
    Hello, I am curious what is your opinion on Room associative entities (linking table and JOIN query) versus joining tables manually (flapMapLatest/switchMap) what approach do you prefer and why?
    y
    • 2
    • 1
  • c

    Chris Fillmore

    08/13/2021, 3:27 PM
    Hello folks, happy Friday. Question: is it possible for a Room db entity to have a field that is a
    value class
    ? For example:
    @Entity
    data class Order(id: OrderId)
    
    @JvmInline
    value class OrderId(val value: String)
    When I do this, I get an error at build time:
    Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
    Another error says:
    Cannot find getter for field.
    I am using Room v2.3.0 Thanks for any help!
    y
    • 2
    • 2
  • m

    Marcin Środa

    09/03/2021, 1:59 PM
    Hi, I get stuck with Relations in Room. Trying to connect channel and members, based on memberships. Let’s say that the structure is:
    data class Membership(
        @PrimaryKey
        val id: String,
        val channel: String, // channelId
        val member: String, // memberId
    )
    data class Channel(
        @PrimaryKey val id: String,
        val name: String,
        ...
    )
    data class Member(
        @PrimaryKey val id: String,
        override val name: String,
        ...
    )
    Is it possible to create a
    ChannelWithMembers
    and
    MemberWithChannels
    with relations?
    y
    • 2
    • 3
  • m

    Mini

    09/28/2021, 8:23 AM
    Trying to use KSP for room (2.4.0-alpha04), ksp 1.5.31-1.0.0, and getting this error ” Schema export directory is not provided to the annotation processor so we cannot import the schema. To generate auto migrations, you must provide
    room.schemaLocation
    annotation processor argument AND set exportSchema to true.” I have room.schemaLocation like Ive had before, so I guess ksp needs it passed differently. Could someone tell me how? also getting “Cannot figure out how to save this field into database. You can consider adding a type converter for it.” despite having a typeconverter for the field
    y
    • 2
    • 5
  • m

    ms

    09/28/2021, 9:13 AM
    When can we expect Room with a stable KSP support? I see it's already been integrated. Is there any roadmap for that?
    y
    • 2
    • 2
  • k

    Khan

    10/26/2021, 12:25 PM
    Hi, Should we add @Keep with @Entity to avoid obfuscation. I assume data class with @Entity should not get obfuscated but in some cases it does.
    @Entity
    data class Employees(
        @PrimaryKey val id: String, val name: String?
    )
    Thanks 🙂
    y
    • 2
    • 2
  • w

    William Reed

    10/26/2021, 5:27 PM
    does room handle
    value class
    automatically or do i need to manually make a converter?
    m
    • 2
    • 1
  • a

    Aidan Low

    11/08/2021, 6:53 PM
    Does Room conflict with
    -Xjvm-default=all
    and
    -Xjvm-default=all-compatibility
    ? Using version 2.3, if I add either of those flags then when I compile my
    MyDao.kt
    the generated
    MyDao_Impl.java
    for each overriden method
    foo()
    contains calls to
    MyDao.super.foo()
    rather than calling
    MyDao.DefaultImpls.foo()
    as it did when I specified
    -Xjvm-default=enabled
    , leading to compilation errors
    error: not an enclosing class: MyDao
            return MyDao.super.foo(__cont);
                        ^
    • 1
    • 1
  • t

    Tower Guidev2

    11/19/2021, 1:32 PM
    Hi, I just got here 😄
    • 1
    • 1
  • k

    KV

    11/26/2021, 2:24 PM
    Hey people I have a question regarding migrations: For example I have 1 table with 5 column and one of the column stored the string which is coming from the BE Column 1 - id Column 2 - name Column 3- type -> json type (text) now from the BE response we are getting normal type as string Column 3 - type -> string (text) So how to map the data? If I am on 1st version of migration, I have json string and now when I switch to new version & I have a string type data.In the app, I already stored the old data into table and also new data into table. How app will work? For the 1st time app is crashing so how to handle this situation? We have to map the old data to the new format how to do this ? any other possible way to do that ?
    y
    m
    • 3
    • 2
Powered by Linen
Title
k

KV

11/26/2021, 2:24 PM
Hey people I have a question regarding migrations: For example I have 1 table with 5 column and one of the column stored the string which is coming from the BE Column 1 - id Column 2 - name Column 3- type -> json type (text) now from the BE response we are getting normal type as string Column 3 - type -> string (text) So how to map the data? If I am on 1st version of migration, I have json string and now when I switch to new version & I have a string type data.In the app, I already stored the old data into table and also new data into table. How app will work? For the 1st time app is crashing so how to handle this situation? We have to map the old data to the new format how to do this ? any other possible way to do that ?
y

yigit

12/02/2021, 5:48 PM
Not sure if i follow. What was the kotlin type of that column before and after
m

myanmarking

12/06/2021, 10:41 AM
for that auto-migration won’t solve your problem 😛 You don’t need a migration, just a simple data update
View count: 8