Usage

Creating a schema

import { BaseSchema, RealmProperty, RealmSchema } from 'react-native-realm-schema';
import nameof from 'ts-nameof.macro';

@RealmSchema({
  // name of the schema
  name: nameof(DeviceSchema),
  // primary key
  primaryKey: nameof(DeviceSchema.prototype._id),
})
export class DeviceSchema extends BaseSchema {
  @RealmProperty(/* dataType */ 'uuid', /* isRequired */ true)
  public _id: string;

  @RealmProperty('string')
  public name: string;

  @RealmProperty('string')
  public status?: string;
}

Get schema object

const schema = DeviceSchema.schema;

Create new schema object

const deviceSchema = DeviceSchema.create();

Schema name

const schemaName = DeviceSchema.schemaName;

Initialize Realm

import { RealmDatabase, schemaListOf } from 'src/helpers';

class Database extends RealmDatabase {
  public get schemas() {
    return schemaListOf(
      DeviceSchema,
      // ...
    );
  }

  public get path(): string {
    return 'my_realm'
  }
}

const database = new Database();

/**
 * Initialize the database
 */
const realm = await database.init();

// or access using getter
database.realm;