commonMain.io.realm.kotlin.mongodb.RealmExt.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of library-sync-jvm Show documentation
Show all versions of library-sync-jvm Show documentation
Sync Library code for Realm Kotlin. This artifact is not supposed to be consumed directly, but through 'io.realm.kotlin:gradle-plugin:1.5.2' instead.
The newest version!
/*
* Copyright 2022 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.realm.kotlin.mongodb
import io.realm.kotlin.Realm
import io.realm.kotlin.mongodb.internal.SyncedRealmContext
import io.realm.kotlin.mongodb.internal.executeInSyncContext
import io.realm.kotlin.mongodb.sync.SubscriptionSet
import io.realm.kotlin.mongodb.sync.SyncMode
import io.realm.kotlin.mongodb.sync.SyncSession
/**
* This class contains extension methods that are available when using synced realms.
*
* Calling these methods on a local realms created using a [io.realm.RealmConfiguration] will
* throw an [IllegalStateException].
*/
/**
* Returns the [SyncSession] associated with this Realm.
*/
public val Realm.syncSession: SyncSession
get() {
return executeInSyncContext(this) { context: SyncedRealmContext ->
context.session
}
}
/**
* Returns the latest [SubscriptionSet] associated with this Realm.
*/
public val Realm.subscriptions: SubscriptionSet
get() {
return executeInSyncContext(this) { context: SyncedRealmContext ->
if (context.config.syncMode != SyncMode.FLEXIBLE) {
throw IllegalStateException(
"Subscriptions are only available on Realms configured " +
"for Flexible Sync. This Realm was configured for Partition-based Sync: " +
"${context.config.path}"
)
}
context.subscriptions
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy