Related Classes
Members
The default path where to create and access the Realm file.
Type:
string
Constructor
- config optional
- Type:
Configuration
Required when first creating the Realm.
Create a new Realm
instance using the provided config
. If a Realm does not yet exist
at config.path
(or Realm.defaultPath
if not provided), then this constructor
will create it with the provided config.schema
(which is required in this case).
Otherwise, the instance will access the existing Realm from the file at that path.
In this case, config.schema
is optional or not have changed, unless
config.schemaVersion
is incremented, in which case the Realm will be automatically
migrated to use the new schema.
Parameters:
Methods
- path
- Type:
string
The path to the file where the Realm database is stored.
- encryptionKey optional
- Type:
ArrayBuffer
orArrayBufferView
Required only when accessing encrypted Realms.
-
Error
When passing an invalid or non-matching encryption key.
- name
- Type:
string
The name of event that should cause the callback to be called. Currently, only the "change" event supported.
- callback
- Type:
function
Function to be called when the event occurs. Each callback will only be called once per event, regardless of the number of times it was added.
-
Error
If an invalid event
name
is supplied, or ifcallback
is not a function.
- type
- Type:
ObjectType
The type of Realm object to create.
- properties
- Type:
Object
Property values for all required properties without a default value.
- update optional
- Type:
boolean
- Default:
false
Signals that an existing object with matching primary key should be updated. Only the primary key property and properties which should be updated need to be specified. All missing property values will remain unchanged.
- object
- Type:
Realm.Object
or[Realm.Object, ...]
orRealm.List
orRealm.Results
- type
- Type:
ObjectType
The type of Realm objects to retrieve.
-
Error
If type passed into this method is invalid.
- name optional
- Type:
string
The name of the event whose listeners should be removed. Currently, only the "change" event supported.
-
Error
When invalid event
name
is supplied
- name
- Type:
string
The event name. Currently, only the "change" event supported.
- callback
- Type:
function
Function that was previously added as a listener for this event through the
addListener
method.-
Error
If an invalid event
name
is supplied, or ifcallback
is not a function.
- callback
- Type:
function
number
Get the current schema version of the Realm at the given path.
Parameters:
Throws:
number
version of the schema, or -1
if no Realm exists at path
.
Add a listener callback
for the specified event name
.
Parameters:
Throws:
Realm.Object
Create a new Realm object of the given type and with the specified properties.
Parameters:
Realm.Object
Deletes the provided Realm object, or each one inside the provided collection.
Parameters:
WARNING: This will delete all objects in the Realm!
Realm.Results
Returns all objects of the given type
in the Realm.
Parameters:
Throws:
Realm.Results
that will live-update as objects are created and destroyed.
Remove all event listeners (restricted to the event name
, if provided).
Parameters:
Throws:
Remove the listener callback
for the specfied event name
.
Parameters:
Throws:
Synchronously call the provided callback
inside a write transaction.
Parameters:
Type Definitions
- encryptionKey optional
- Type:
ArrayBuffer
orArrayBufferView
The 512-bit (64-byte) encryption key used to encrypt and decrypt all data in the Realm.
- path optional
- Type:
string
- Default:
Realm.defaultPath
The path to the file where the Realm database should be stored.
- schema optional
- Type:
[(ObjectClass | ObjectSchema), ...]
Specifies all the object types in this Realm. Required when first creating a Realm at this
path
.- schemaVersion optional
- Type:
number
Required (and must be incremented) after changing the
schema
.- schema
- Type:
ObjectSchema
Static property specifying object schema information.
- name
- Type:
string
Represents the object type.
- primaryKey optional
- Type:
string
The name of a
"string"
or"int"
property that must be unique across all objects of this type within the same Realm.- properties
- Type:
{<string>: (PropertyType | ObjectSchemaProperty), ...}
An object where the keys are property names and the values represent the property type.
- type
- Type:
PropertyType
The type of this property.
- objectType optional
- Type:
string
Required when
type
is"list"
, and must match the type of an object in the same schema.- default optional
- Type:
any
The default value for this property on creation when not otherwise specified.
- optional optional
- Type:
boolean
Signals if this property may be assigned
null
orundefined
.- indexed optional
- Type:
boolean
Signals if this property should be indexed. Only supported for
"string"
,"int"
, and"bool"
properties.- "bool"
- Type:
boolean
Property value may either be
true
orfalse
.- "int"
- Type:
number
Property may be assigned any number, but will be stored as a round integer, meaning anything after the decimal will be truncated.
- "float"
- Type:
number
Property may be assigned any number, but will be stored as a
float
, which may result in a loss of precision.- "double"
- Type:
number
Property may be assigned any number, and will have no loss of precision.
- "string"
- Type:
string
Property value may be any arbitrary string.
- "date"
- Type:
Date
Property may be assigned any
Date
instance, but will be stored with second-level precision (a fix for this is in progress).- "data"
- Type:
ArrayBuffer
Property may either be assigned an
ArrayBuffer
orArrayBufferView
(e.g.DataView
,Int8Array
,Float32Array
, etc.) instance, but will always be returned as anArrayBuffer
.- "list"
- Type:
Realm.List
Property may be assigned any ordered collection (e.g.
Array
,Realm.List
,Realm.Results
) of objects all matching theobjectType
specified in theObjectSchemaProperty
.- "<ObjectType>"
- Type:
Realm.Object
A string that matches the
name
of an object in the same schema (seeObjectSchema
) – this property may be assigned any object of this type from inside the same Realm, and will always be optional (meaning it may also be assignednull
orundefined
).
This describes the different options used to create a Realm
instance.
Type:
Object
Properties:
Realm objects will inherit methods, getters, and setters from the prototype
of this
constructor.
Type:
Class
Properties:
Type:
Object
Properties:
Type:
Object
Properties:
The type of an object may either be specified as a string equal to the name
in a
ObjectSchema
definition, or a constructor that was specified
in the configuration
schema
.
A property type may be specified as one of the standard builtin types, or as an object type inside the same schema.
Type:
"bool"
or "int"
or "float"
or "double"
or "string"
or "date"
or "data"
or "list"
or "<ObjectType>"