mrphu3074 / react-native-realm-model

Model wrapper for react native Realm
13 stars 2 forks source link

React native Realm Model

RealmModel is a wrapper for realm.

CHANGELOG

How it works

import Realm from 'realm';
import RealmModel from 'react-native-realm-model';
const realm = new Realm({
  schema: [{
    name: 'Product',
    properties: {
      title: 'string',
      content: {
        type: 'string',
        optional: true
      },
      price: 'int'
    }
  }]
})

class Product extends RealmModel {
  static realm = realm;
  // custom methods
  priceLabel() {
    return this.price + 'vnđ';
  }
}

Product.insert({title: 'Product 1', content: 'This is content', price: 22000});
var product = Product.findOne();

console.log(product.priceLabel());

product.update({price: 24000})

console.log(product.priceLabel());

product.remove();

API

find(selector: Object, option: Object) -> Array

findOne(selector: Object)

insert(data: Object)

update(selector: Object, modifier: Object)

remove(selector: Object)