Realm

interface Realm : TypedRealm

A Realm instance is the main entry point for interacting with a persisted realm.

See also

Types

Companion
Link copied to clipboard
object Companion

Functions

asFlow
Link copied to clipboard
abstract fun asFlow(): <ERROR CLASS><RealmChange<Realm>>

Observe changes to the realm. The flow will emit a RealmChange once subscribed and then, on every change to the realm. The flow will continue running indefinitely until canceled or the realm instance is closed.

close
Link copied to clipboard
abstract fun close()

Close this realm and all underlying resources. Accessing any methods or Realm Objects after this method has been called will then an IllegalStateException.

copyFromRealm
Link copied to clipboard
abstract fun <T : TypedRealmObject> copyFromRealm(obj: T, depth: UInt = UInt.MAX_VALUE): T

Makes an unmanaged in-memory copy of an already persisted io.realm.kotlin.types.RealmObject. This is a deep copy that will copy all referenced objects.

abstract fun <T : TypedRealmObject> copyFromRealm(dictionary: RealmDictionary<T?>, depth: UInt = UInt.MAX_VALUE): Map<String, T?>

Makes an unmanaged in-memory copy of a RealmDictionary of already persisted io.realm.kotlin.types.RealmObjects. This is a deep copy that will copy all referenced objects.

abstract fun <T : TypedRealmObject> copyFromRealm(collection: Iterable<T>, depth: UInt = UInt.MAX_VALUE): List<T>

Makes an unmanaged in-memory copy of a collection of already persisted io.realm.kotlin.types.RealmObjects. This is a deep copy that will copy all referenced objects.

getNumberOfActiveVersions
Link copied to clipboard
abstract fun getNumberOfActiveVersions(): Long

Returns the current number of active versions in the Realm file. A large number of active versions can have a negative impact on the Realm file size on disk.

isClosed
Link copied to clipboard
abstract fun isClosed(): Boolean

Check if this Realm has been closed or not. If the Realm has been closed, most methods will throw IllegalStateException if called.

query
Link copied to clipboard
abstract override fun <T : TypedRealmObject> query(clazz: KClass<T>, query: String, vararg args: Any?): RealmQuery<T>

Returns a RealmQuery matching the predicate represented by query.

schema
Link copied to clipboard
abstract fun schema(): RealmSchema

Returns an immutable schema of the realm.

schemaVersion
Link copied to clipboard
abstract fun schemaVersion(): Long

Returns the schema version of the realm.

version
Link copied to clipboard
abstract fun version(): VersionId

Returns the Realm version of this object. This version number is tied to the transaction the object was read from.

write
Link copied to clipboard
abstract suspend fun <R> write(block: MutableRealm.() -> R): R

Modify the underlying Realm file in a suspendable transaction on the default Realm Write Dispatcher.

writeBlocking
Link copied to clipboard
abstract fun <R> writeBlocking(block: MutableRealm.() -> R): R

Modify the underlying Realm file while blocking the calling thread until the transaction is done. Write transactions automatically commit any changes made when the closure returns unless MutableRealm.cancelWrite was called.

writeCopyTo
Link copied to clipboard
abstract fun writeCopyTo(targetConfiguration: Configuration)

Writes a compacted copy of the Realm to the given destination as defined by the targetConfiguration. The resulting file can be used for a number of purposes:

Properties

configuration
Link copied to clipboard
abstract val configuration: Configuration

Configuration used to configure this Realm instance.

Extensions

query
Link copied to clipboard
inline fun <T : TypedRealmObject> Realm.query(query: String = TRUE_PREDICATE, vararg args: Any?): RealmQuery<T>

Returns a RealmQuery matching the predicate represented by query.