Type alias BaseConfiguration

BaseConfiguration: {
    deleteRealmIfMigrationNeeded?: boolean;
    disableFormatUpgrade?: boolean;
    encryptionKey?: ArrayBuffer | ArrayBufferView | Int8Array;
    fifoFilesFallbackPath?: string;
    inMemory?: boolean;
    migrationOptions?: MigrationOptions;
    onFirstOpen?: ((realm) => void);
    onMigration?: MigrationCallback;
    path?: string;
    readOnly?: boolean;
    schema?: (RealmObjectConstructor<AnyRealmObject> | ObjectSchema)[];
    schemaVersion?: number;
    shouldCompact?: ((totalBytes, usedBytes) => boolean);
    sync?: SyncConfiguration;
}

The options used to create a Realm instance.

Type declaration

  • Optional deleteRealmIfMigrationNeeded?: boolean

    Specifies if this Realm should be deleted if a migration is needed. The option is incompatible with option sync. @default: false

    Since

    1.13.0

  • Optional disableFormatUpgrade?: boolean

    Specifies if this Realm's file format should be automatically upgraded if it was created with an older version of the Realm library. If set to true and a file format upgrade is required, an error will be thrown instead.

    Default

    false
    

    Since

    2.1.0

  • Optional encryptionKey?: ArrayBuffer | ArrayBufferView | Int8Array

    The 512-bit (64-byte) encryption key used to encrypt and decrypt all data in the Realm.

    Since

    0.11.1

  • Optional fifoFilesFallbackPath?: string

    Opening a Realm creates a number of FIFO special files in order to coordinate access to the Realm across threads and processes. If the Realm file is stored in a location that does not allow the creation of FIFO special files (e.g. FAT32 file systems), then the Realm cannot be opened. In that case Realm needs a different location to store these files and this property defines that location. The FIFO special files are very lightweight and the main Realm file will still be stored in the location defined by the path property. This property is ignored if the directory defined by path allow FIFO special files.

    Since

    2.23.0

  • Optional inMemory?: boolean

    Specifies if this Realm should be opened in-memory. This still requires a path (can be the default path) to identify the Realm so other processes can open the same Realm. The file will also be used as swap space if the Realm becomes bigger than what fits in memory, but it is not persistent and will be removed when the last instance is closed. This option is incompatible with option sync.

    Default

    false
    

    Since

    0.10.0

  • Optional migrationOptions?: MigrationOptions
  • Optional onFirstOpen?: ((realm) => void)

    The function called when opening a Realm for the first time. The function can populate the Realm prior to opening it. When calling the callback, the Realm will be in a write transaction.

    Param: realm

    The newly created Realm.

    Since

    10.14.0

      • (realm): void
      • The function called when opening a Realm for the first time. The function can populate the Realm prior to opening it. When calling the callback, the Realm will be in a write transaction.

        Parameters

        • realm: Realm

          The newly created Realm.

        Returns void

        Since

        10.14.0

  • Optional onMigration?: MigrationCallback

    The function to run if a migration is needed.

    This function should provide all the logic for converting data models from previous schemas to the new schema. This option is incompatible with option sync.

    The function takes two arguments:

    • oldRealm - The Realm before migration is performed.
    • newRealm - The Realm that uses the latest schema, which should be modified as necessary.

    Since

    0.12.0

  • Optional path?: string

    The path to the file where the Realm database should be stored. For synced Realms, a relative path is used together with the AppConfiguration and User.id in order to avoid collisions with other apps or users. An absolute path is left untouched and on some platforms (iOS and Android) the app might not have permissions to create or open the file - permissions are not validated. If a relative path is specified, it is relative to AppConfiguration.baseFilePath.

    Since

    0.10.0

  • Optional readOnly?: boolean

    Specifies if this Realm should be opened as read-only.

    Default

    false
    

    Since

    0.10.0

  • Optional schema?: (RealmObjectConstructor<AnyRealmObject> | ObjectSchema)[]

    Specifies all the object types in this Realm. Required when first creating a Realm at this path. If omitted, the schema will be read from the existing Realm file.

    Since

    0.10.0

  • Optional schemaVersion?: number

    If changing the schema, this field is required and must be incremented. This only applies to local Realms.

    Since

    0.11.0

  • Optional shouldCompact?: ((totalBytes, usedBytes) => boolean)

    The function called when opening a Realm for the first time during the life of a process to determine if it should be compacted before being returned to the user.

    It returns true to indicate that an attempt to compact the file should be made. The compaction will be skipped if another process is accessing it.

    Param: totalBytes

    The total file size (data + free space).

    Param: usedBytes

    The total bytes used by data in the file.

    Returns

    true if Realm file should be compacted before opening.

    Since

    2.9.0

    Example

    // compact large files (>100 MB) with more than half is free space
    shouldCompact: (totalBytes, usedBytes) => {
    const oneHundredMB = 100 * 1024 * 1024; // 100 MB
    return totalBytes > oneHundredMB && usedBytes / totalBytes < 0.5;
    }
      • (totalBytes, usedBytes): boolean
      • The function called when opening a Realm for the first time during the life of a process to determine if it should be compacted before being returned to the user.

        It returns true to indicate that an attempt to compact the file should be made. The compaction will be skipped if another process is accessing it.

        Parameters

        • totalBytes: number

          The total file size (data + free space).

        • usedBytes: number

          The total bytes used by data in the file.

        Returns boolean

        true if Realm file should be compacted before opening.

        Since

        2.9.0

        Example

        // compact large files (>100 MB) with more than half is free space
        shouldCompact: (totalBytes, usedBytes) => {
        const oneHundredMB = 100 * 1024 * 1024; // 100 MB
        return totalBytes > oneHundredMB && usedBytes / totalBytes < 0.5;
        }
  • Optional sync?: SyncConfiguration

Generated using TypeDoc