forked from pubkey/rxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
46 lines (41 loc) · 1.13 KB
/
database.js
File metadata and controls
46 lines (41 loc) · 1.13 KB
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
46
const { createRxDatabase, addRxPlugin } = require('rxdb');
const { RxDBQueryBuilderPlugin } = require('rxdb/plugins/query-builder');
const { RxDBDevModePlugin } = require('rxdb/plugins/dev-mode');
const { addPouchPlugin, getRxStoragePouch } = require('rxdb/plugins/pouchdb');
addRxPlugin(RxDBQueryBuilderPlugin);
addRxPlugin(RxDBDevModePlugin);
addPouchPlugin(require('pouchdb-adapter-memory'));
addPouchPlugin(require('pouchdb-adapter-http'));
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 createDatabase(name, adapter) {
const db = await createRxDatabase({
name,
storage: getRxStoragePouch(adapter)
});
console.log('creating hero-collection..');
await db.addCollections({
heroes: {
schema: heroSchema
}
});
return db;
}
module.exports = {
createDatabase
};