vn-verdnaturachat/app/realm.js

84 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-08-03 18:23:43 +00:00
import Realm from 'realm';
const serversSchema = {
name: 'servers',
primaryKey: 'id',
properties: {
id: 'string',
current: 'bool'
}
};
const settingsSchema = {
name: 'settings',
primaryKey: '_id',
properties: {
_id: 'string',
value: {type: 'string', optional: true}
}
};
const subscriptionSchema = {
name: 'subscriptions',
primaryKey: '_id',
properties: {
_id: 'string',
t: 'string',
ts: 'date',
ls: 'date',
name: 'string',
fname: {type: 'string', optional: true},
rid: 'string',
// u: { _id: 'hKCY2XGzHYk89SAaM', username: 'rodrigo', name: null },
open: 'bool',
alert: 'bool',
// roles: [ 'owner' ],
unread: 'int'
// userMentions: 0,
// groupMentions: 0,
// _updatedAt: Fri Jul 28 2017 18:31:35 GMT-0300 (-03),
}
};
2017-08-04 00:34:37 +00:00
const usersSchema = {
name: 'users',
primaryKey: '_id',
properties: {
_id: 'string',
username: 'string',
name: {type: 'string', optional: true}
}
}
const messagesSchema = {
name: 'messages',
primaryKey: '_id',
properties: {
_id: 'string',
msg: {type: 'string', optional: true},
rid: 'string',
ts: 'date',
u: 'users',
// mentions: [],
// channels: [],
_updatedAt: 'date'
}
};
2017-08-03 18:23:43 +00:00
// Realm.clearTestState();
const realm = new Realm({
2017-08-04 00:34:37 +00:00
schema: [settingsSchema, serversSchema, subscriptionSchema, messagesSchema, usersSchema]
2017-08-03 18:23:43 +00:00
});
export default realm;
// Clear settings
realm.write(() => {
const allSettins = realm.objects('settings');
realm.delete(allSettins);
});
console.log(realm.objects('servers'));