0.0.10 • Published 8 years ago

react-native-realm-model v0.0.10

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

React native Realm Model

RealmModel is a wrapper for realm.

CHANGELOG

  • 0.0.10

    • Fixed some bugs
    • Supported model events: beforeInsert, afterInsert, beforeUpdate, afterUpdate, beforeRemove, afterRemove

      class Product extends RealmModel {
          static realm = realm;
      
          static beforeInsert(doc) {
              doc.createdAt = doc.updatedAt = new Date();
              return doc;
          }
      }

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

  • selector is search criteria

    	- Type 1: `{field: value}` 
    	- Type 2: logical operator `{$or: [{field1: value1, field2: value2}]}`
    	- Type 3: realm operator `==`, `>=`, `<=`, `>`, `<`, `BEGINSWITH`, `ENDSWITH`, `CONTAINS` and string comparisons can be made case insensitive by appending `[c]` to the operator: `==[c]`, `BEGINSWITH[c]` etc.
    
    	 Ex: `Product.find({title: {'BEGINSWITH[c]': 'hello'}})`
  • option is search option support: limit, offset, sort

findOne(selector: Object)

insert(data: Object)

update(selector: Object, modifier: Object)

remove(selector: Object)

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago