-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
shared.js
45 lines (38 loc) · 941 Bytes
/
shared.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { createRxDatabase, addRxPlugin } = require('rxdb');
const { RxDBQueryBuilderPlugin } = require('rxdb/plugins/query-builder');
const { RxDBDevModePlugin } = require('rxdb/plugins/dev-mode');
addRxPlugin(RxDBQueryBuilderPlugin);
addRxPlugin(RxDBDevModePlugin);
const heroSchema = {
title: 'hero schema',
description: 'describes a simple hero',
version: 0,
primaryKey: 'name',
type: 'object',
properties: {
name: {
type: 'string',
maxLength: 100
},
color: {
type: 'string'
}
},
required: ['name', 'color']
};
async function getDatabase(name, storage) {
const db = await createRxDatabase({
name,
storage
});
console.log('creating hero-collection..');
await db.addCollections({
heroes: {
schema: heroSchema
}
});
return db;
}
module.exports = {
getDatabase
};