1 |
|
2 |
|
3 | const PouchDB = require('pouchdb')
|
4 | require('pouchdb/extras/memory') |
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const db = new PouchDB('test', {adapter: 'memory'})
|
11 |
|
12 |
|
13 | let response = await db.put({
|
14 | _id: 'mydoc',
|
15 | title: 'Heroes'
|
16 | })
|
17 |
|
18 |
|
19 | await db.put({
|
20 | _id: 'mydoc',
|
21 | _rev: response.rev,
|
22 | title: "Sound and Vision",
|
23 | })
|
24 |
|
25 |
|
26 | console.log(await db.get('mydoc'))
|
27 |
|
28 |
|
29 | response = await db.bulkDocs([
|
30 | {_id: 'myotherdoc', title: 'The Magisters', type: "fake band"},
|
31 | {_id: 'another', title: 'Kowabunga', type: "fake band"},
|
32 | {title: 'Without an _id', type: null}
|
33 | ])
|
34 |
|
35 | console.log('bulkDocs response: ' + JSON.stringify(response, null, 2))
|
36 |
|
37 |
|
38 | await db.put({
|
39 | _id: '_design/fakebands',
|
40 | views: {
|
41 | fakebands: {
|
42 | map: (function (doc) {
|
43 | if (doc.type == "fake band") {
|
44 | emit(doc.title)
|
45 | }
|
46 | }).toString()
|
47 | }
|
48 | }
|
49 | })
|
50 | await db.query('fakebands', {include_docs: true})
|