RealmModel is a wrapper for realm.
0.0.10
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;
}
}
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();
selector is search criteria
{field: value}
{$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'}})
limit
, offset
, sort