https://kotlinlang.org logo
Join SlackCommunities
Powered by
# realm
  • j

    John O'Reilly

    05/24/2023, 5:54 PM
    Any plans to create wasm target for realm kotlin?
    👀 2
    c
    • 2
    • 3
  • c

    chrmelchior

    05/25/2023, 11:09 AM
    We just released Realm Kotlin 1.9 with support for Kotlin Serialization, bundled realm files and simple full-text search: https://github.com/realm/realm-kotlin/blob/releases/CHANGELOG.md#190-2023-05-23 Note, we also bumped the supported version of Kotlin from 1.7.20 to 1.8, which will allow us to use the new android source sets in a future release.
    🙌 1
    ✅ 1
  • t

    Thiago Delgado

    06/09/2023, 1:40 PM
    Hi team! Thiago Delgado here, currently working in a big realm project. Not sure if this is the right place to ask but, is there an plan to add a feature similar to a view or a projection that can include multiple collections? I'm using the kotlin sdk btw
    c
    • 2
    • 1
  • c

    Christos Savlidis

    07/27/2023, 1:51 PM
    Hey guys, what is the best way to access Realm for anywhere in the app? I don’t think calling the
    Realm.open(getRealmUnEncryptedConfig())
    every time is correct
    j
    • 2
    • 4
  • g

    Grzegorz Gajewski

    07/28/2023, 2:14 PM
    Hey guys. I’m currently working on the realm SDK migration from Java to Kotlin. In the migration docs there is this line:
    Copy code
    The Kotlin SDK does not provide the ability to set and access a default realm in your application. Since you can now share realms, objects, and results across threads, you can rely on a global singleton instead.
    So I went with global singleton. But I don’t think this works like I thought it would (similar to room) as now I’m getting:
    Copy code
    java.lang.IllegalStateException: [RLM_ERR_WRONG_TRANSACTION_STATE]: The Realm is already in a write transaction
    I have a background sync that might write at any given moment, should I open another Realm for that in this case to avoid this crash?
    ✅ 1
    z
    c
    • 3
    • 3
  • j

    John O'Reilly

    07/30/2023, 12:16 PM
    Any known issues using K2 compiler with Realm Kotlin? Still investigating but getting errors when I enabled it for a couple of KMP samples using Realm
    c
    • 2
    • 6
  • d

    Daniel

    07/31/2023, 7:56 PM
    How it is possible that the current user
    appService.currentUser
    is null for some users after they already login? this will cause the app to crash because I really dont know a good way or flow to handle when it is null, I dont even know how its possible to be null, because I do not delete the users nor the token refresh expires. the code:
    Copy code
    fun getUserProfile(): CommonFlow<UserInfo?> {
            val userId = appService.currentUser!!.id
    
            val user = realm.query<UserInfo>("_id = $0", userId).asFlow().map {
                it.list.firstOrNull()
            }.asCommonFlow()
    
            return user
        }
    how is it possible to be null?
    c
    • 2
    • 1
  • g

    Grzegorz Gajewski

    08/01/2023, 7:23 AM
    Is there a way to do an
    OR
    between two subqueries? I have a big query with subqueries build like this:
    Copy code
    var query = query<Model>("id == $0", id)
            if (otherModelId != null) {
                query = query.query("otherModel.id == $0", otherModelId)
            }
            if (markedOnly) {
                query = query("flagged == $0", true)
            }
    And now I need to add OR to the top level query.
    c
    • 2
    • 2
  • t

    Thiago Delgado

    08/09/2023, 11:17 PM
    Folks, I'm using realm-kotlin to build an android app and recently I started having troubles running the app on offline mode. I keep getting errors while Realm tries to reestablish the sync session (Unknown 4400 Websocket Resolve Failed) and my queries doesn't resolve... Any idea on how to fix this or where should I look first? Using realm 1.10.2 now
    c
    • 2
    • 5
  • g

    Grzegorz Gajewski

    08/10/2023, 9:26 AM
    Hey guys. We found this issue but we are not sure if we are missing some understanding or is it really a regression?
    c
    • 2
    • 2
  • t

    Thiago Delgado

    08/10/2023, 8:45 PM
    Hi folks, anyone else having troubles deleting a Realm? (https://github.com/realm/realm-kotlin/issues/1425 – probably related)
  • g

    Grzegorz Gajewski

    08/25/2023, 11:30 AM
    I’m trying to fight large number of active realm version after migration. I created this sample to try to understand it better. No matter what I do I cannot get the number down. I tried different realm versions
    1.7.0
    and latest
    1.10.2
    . When I remove the code to collect the flow and run GC manually it drops (but only in
    1.7.0
    ). What am I missing here? What are the strategies that we can use today to keep active realm versions low?
    Copy code
    object Singleton {
        val config = RealmConfiguration.create(schema = setOf(Item::class))
        val realm = Realm.open(config)
    }
    
    class Item : RealmObject {
        @PrimaryKey
        var _id: ObjectId = ObjectId()
        var isComplete: Boolean = false
        var summary: String = ""
        var owner_id: String = ""
    }
    
    class MainActivity : ComponentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            val objectsCount = mutableStateOf(0L)
            val versionsCount = mutableStateOf(realm.getNumberOfActiveVersions())
            setContent {
                RealmTestTheme {
                    // A surface container using the 'background' color from the theme
                    Surface(
                        modifier = Modifier.fillMaxSize(),
                        color = MaterialTheme.colorScheme.background
                    ) {
                        Greeting(objectsCount.value.toString(), versionsCount.value.toString(), onClick = {
                            lifecycleScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
                                repeat(100) {
                                    realm.write {
                                        copyToRealm(Item().apply {
                                            summary = "Do the laundry"
                                            isComplete = false
                                        })
                                    }
                                    delay(10)
                                    versionsCount.value = realm.getNumberOfActiveVersions()
                                }
                            }
                        })
                    }
                }
            }
            realm
                .query<Item>()
                .asFlow()
                .onEach {
                    val summaries = it.list.map { it.summary }
                    objectsCount.value = summaries.count().toLong()
                }
                .flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
                .launchIn(lifecycleScope)
        }
    }
    
    @Composable
    fun Greeting(objectsCount: String, activeVersions: String, modifier: Modifier = Modifier, onClick: () -> Unit) {
            Column() {
                Text(
                    text = "Objects $objectsCount",
                    modifier = modifier
                )
                Text(
                    text = "Active versions $activeVersions",
                    modifier = modifier
                )
                Button(onClick = onClick) {
                    Text(text = "Insert 100 items")
                }
            }
    }
    c
    • 2
    • 1
  • b

    benkuly

    10/12/2023, 3:20 PM
    What is the behaviour of realm-kotlin, when an app (Android) is killed while a tranasction is running?
    c
    • 2
    • 3
  • d

    dephinera

    10/17/2023, 8:23 AM
    Hey, guys, We’re about to integrate the Realm DB and we noticed that there isn’t an auto-close mechanism. Could you share what approaches do you take to manage the db? Do you try to close it on app close, or perhaps you’ve implemented something with a timeout?
    g
    • 2
    • 6
  • c

    Christopher Mederos

    10/20/2023, 12:54 AM
    Is there any way to pass a map or list or query parameter values to realm's query function? The documents make it seem like you must construct a query string and varargs for exactly the number of parameters you want to query:
    "progressMinutes > $0 AND assignee == $1", 1, "Alex"
    Ideally, is there a similar syntax available like
    "progressMinutes > $0 AND assignee == $1", queryParams.values
    ?
    • 1
    • 2
  • b

    BaBeStudios

    11/08/2023, 12:07 PM
    Calling RealmInstant.now() in Android 7 (API 25) and below will fail with the following exception:
    Copy code
    Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.Clock" on path: DexPathList[[zip file "/data/app/[...]split_config.xxxhdpi.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
        dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        io.realm.kotlin.internal.platform.SystemUtilsKt.currentTime(SystemUtils.kt:32)
        io.realm.kotlin.types.RealmInstant$Companion.now(RealmInstant.kt:87)
    Clock was added in API 26 for Android. Is there a way to mitigate this, or is the minimum Android SDK version for the Kotlin SDK effectively API level 26? I'm writing this before looking into replacing RealmInstant or the call to systemUTC(), that causes the Exception.
    n
    • 2
    • 2
  • c

    chrmelchior

    12/04/2023, 1:26 PM
    We released Realm Kotlin 1.13.0 last week. It has support for Kotlin 1.9.20 and the K2 compiler. Given the current state of K2, we would be interested in any cases where it does not work so we can either fix it or make JetBrains aware of it 🙏 https://github.com/realm/realm-kotlin/blob/main/CHANGELOG.md#1130-2023-12-01
    🎉 4
  • c

    Christopher Mederos

    12/20/2023, 6:18 AM
    I'm having trouble understanding some realm behaviour. • I query for a count of records where an index value equals some value • I write another record with that same index value • I query again, but the count is unchanged. • I restart the app, and the count is now updated correctly
    c
    • 2
    • 4
  • d

    Daniel

    02/07/2024, 11:31 PM
    Hello, IN operator does not work for realm query:
    Copy code
    suspend fun getRestaurantsProcessedOrdersWithThrowAndroid(): CommonFlow<List<ProcessedOrder>> {
            realm.syncSession.downloadAllServerChanges()
    
            val userId = appService.currentUser
    
            if(appService.currentUser != null) {
                val restaurantsIds = realm.query<Restaurant>("userID = $0", userId!!.id).find().map { it.getID() }
                val queryValues = restaurantsIds.joinToString(separator = ",", prefix = "{", postfix = "}")
                return realm.query<ProcessedOrder>(
                    "restaurantID IN $0", queryValues
                ).asFlow()
                     .map {
                         it.list
                     }.asCommonFlow()
            }
            else{
                throw Exception("user not logged in")
            }
    
        }
    I have tried with listOf("id,"id","id")... Do you know why?
    c
    • 2
    • 1
  • s

    Simon

    04/14/2024, 6:10 AM
    Is there any estimate when 1.15 will be released? Why I am asking is because of the file format changes. I need to keep the iOS version and Android versions in sync (not using Atlas sync yet), but right now the latest versions have different file formats 😕
    c
    • 2
    • 2
  • j

    John O'Reilly

    04/15/2024, 11:57 AM
    Hi, roughly when is it hoped to have version that supports Kotlin/Wasm target?
    c
    • 2
    • 1
  • h

    Hacine Mohamed Abdelhakim

    04/23/2024, 2:16 PM
    any one here tried atlas device sync in production , i have some questions please ?
    c
    • 2
    • 10
  • z

    Zsolt.bertalan

    05/22/2024, 4:19 PM
    Sadly Realm 1.16.0 does not support Kotlin 2.0.0. https://github.com/realm/realm-kotlin/issues/1614 Any chance this will happen any time soon?
    k
    y
    +4
    • 7
    • 28
  • c

    Claus Rørbech

    06/10/2024, 7:41 AM
    We released Realm Kotlin 2.0.0 with support for K2 last week. Highlevel glance of the release are in this blogpost and full details are in the changelog.
    K 2
  • c

    Christopher Mederos

    06/28/2024, 5:22 AM
    ran into an issue today where writes on iOS were silently failing because my KMP class wasn't marked with my serialiser annotation. Eventually I discovered the issue when I tried printing all the values in the DB and then finally saw the serialisation error. In general, is there a way to force / throw write errors in realm?
  • e

    Eduardo Ruesta

    08/19/2024, 7:50 PM
    Hey guys! im working on a Compose Multiplatform project, i have a realm data base, using mongodb too
    • 1
    • 1
  • d

    Daniel

    10/22/2024, 7:00 PM
    Hello, I am using kmm with Realm, but Realm will be deprecated. Any similar DBs that I can migrate? I need fast read/write operations, also auth with FB/Google.
    e
    b
    • 3
    • 8
  • e

    Eduardo Ruesta

    10/23/2024, 3:52 PM
    Hey team! i've been following this tutorial: https://www.mongodb.com/developer/languages/kotlin/mastering-kotlin-creating-api-ktor-mongodb-atlas/. And i used for my BE. I wonder if this use of Mongo DB Atlas will be deprecated too? If yes, which alternatives do i have using Ktor? Thanks
    n
    • 2
    • 1
  • d

    Daniel

    10/28/2024, 6:57 PM
    I have a KMM mobile app focused on regional food delivery. We built it entirely on MongoDB, utilizing Auth, Realm Device Sync, and Triggers. Unfortunately, many of these features will soon be deprecated. What should I migrate to? I’m considering Firebase, but I’m unsure whether to choose Realtime Database or Firestore. Or any other options? I am focused more on speed of db queries. The biggest problem with Realm was the update of realm version that could take minutes for phones that are not up to date and have slow internet connection.
  • p

    Piotr Romanowicz

    01/20/2025, 2:15 PM
    Hey, anyone, anything, about realm & kotlin 2.1.0 support? https://github.com/realm/realm-kotlin/issues/1857
    r
    c
    • 3
    • 3