Rocket.Chat.ReactNative/app/lib/realm.js

90 lines
1.9 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',
2017-08-09 02:27:22 +00:00
_server: 'servers',
2017-08-05 18:16:32 +00:00
value: { type: 'string', optional: true }
2017-08-03 18:23:43 +00:00
}
};
const subscriptionSchema = {
name: 'subscriptions',
primaryKey: '_id',
properties: {
_id: 'string',
2017-08-09 02:27:22 +00:00
_server: 'servers',
2017-08-03 18:23:43 +00:00
t: 'string',
2017-08-07 00:34:35 +00:00
ts: { type: 'date', optional: true },
ls: { type: 'date', optional: true },
2017-08-03 18:23:43 +00:00
name: 'string',
2017-08-05 18:16:32 +00:00
fname: { type: 'string', optional: true },
2017-08-03 18:23:43 +00:00
rid: 'string',
// u: { _id: 'hKCY2XGzHYk89SAaM', username: 'rodrigo', name: null },
2017-08-07 00:34:35 +00:00
open: { type: 'bool', optional: true },
alert: { type: 'bool', optional: true },
2017-08-03 18:23:43 +00:00
// roles: [ 'owner' ],
2017-08-07 00:34:35 +00:00
unread: { type: 'int', optional: true }
2017-08-03 18:23:43 +00:00
// 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',
2017-08-09 02:27:22 +00:00
_server: 'servers',
2017-08-04 00:34:37 +00:00
username: 'string',
2017-08-05 18:16:32 +00:00
name: { type: 'string', optional: true }
2017-08-04 00:34:37 +00:00
}
2017-08-05 18:16:32 +00:00
};
2017-08-04 00:34:37 +00:00
const messagesSchema = {
name: 'messages',
primaryKey: '_id',
properties: {
_id: 'string',
2017-08-09 02:27:22 +00:00
_server: 'servers',
2017-08-05 18:16:32 +00:00
msg: { type: 'string', optional: true },
2017-08-04 00:34:37 +00:00
rid: 'string',
ts: 'date',
u: 'users',
// mentions: [],
// channels: [],
2017-08-09 20:08:50 +00:00
_updatedAt: { type: 'date', optional: true },
2017-08-07 00:34:35 +00:00
temp: { type: 'bool', optional: true }
2017-08-04 00:34:37 +00:00
}
};
2017-08-07 00:34:35 +00:00
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(() => {
2017-08-09 18:15:44 +00:00
// const allSettins = realm.objects('settings');
// realm.delete(allSettins);
2017-08-03 18:23:43 +00:00
2017-08-09 16:19:17 +00:00
// realm.create('servers', { id: 'https://demo.rocket.chat', current: false }, true);
// realm.create('servers', { id: 'http://localhost:3000', current: false }, true);
2017-08-09 02:27:22 +00:00
});