Files
DefinitelyTyped/realm/realm-tests.ts
PishangCode 79e891f647 added type definitions for realm 0.14.3 (#12289)
* added type definitions for realm 0.14.3

* update Results interface

* update tsconfig.json

* remove declare module

* update realm-tests
2016-11-01 21:40:13 +09:00

62 lines
1.1 KiB
TypeScript

import * as Realm from 'realm';
// schema test
const personSchema = {
name: 'Person',
primaryKey: 'id',
properties: {
id: 'int',
name: { type: 'string', default: 'anonymous', indexed: true },
profilePic: { type: 'string', optional: true }
}
};
// encryptionKey
const key = new Int8Array(64);
// constructor test
let realm = new Realm({
schema: [personSchema],
encryptionKey: key
});
realm.write(() => {
// create test
realm.create('Person', {
id: 1,
name: 'Tony'
});
// update test
realm.create('Person', {
id: 1,
name: 'Jack'
}, true);
});
// delete all person test
const allPerson = realm.objects('Person');
realm.delete(allPerson);
// filtered test
const allJack = allPerson.filtered('name = "Jack"');
// sorted test
allJack.sorted('id');
allJack.sorted('id', true);
// limiting results test
allJack.slice(0, 2);
// change events test
realm.addListener('change', () => {
return 'updated';
});
// remove all events
realm.removeAllListeners();
allPerson.find((person: any) => {
return person.name === 'Jack';
});