-
Notifications
You must be signed in to change notification settings - Fork 0
/
services_PouchService.js.html
163 lines (136 loc) · 4.1 KB
/
services_PouchService.js.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: services/PouchService.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: services/PouchService.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import PouchDB from 'pouchdb'
import find from 'pouchdb-find'
PouchDB.plugin(find)
/**
* Provides basic database functionality using PouchDB.
*
* @class
*/
export class PouchService {
/**
* @param {string} dbName - The name of the database to create.
*
* @constructor
*/
constructor (dbName) {
this.db = new PouchDB(dbName)
this.db._remote = false;
}
/**
* Gets the element with the specified ID from the database.
*
* @param {string} id - The ID of the element to get.
* @return {Promise<Object>} A promise to the requested object.
*
* @function
*/
async getOne (id) {
return await this.db.get(id)
}
/**
* Gets all elements from the database.
*
* @return {Promise<Array<Object>>} A promise to an array containing all objects in the database.
*
* @function
*/
async getAll () {
const response = await this.db.find({
selector: {
_id: {
$regex: ''
}
}
})
return response.docs
}
/**
* Adds an index to the database.
*
* @param {string} key - The database field to index.
*
* @function
*/
async addIndex (key) {
this.db.createIndex({
index: { fields: [key] }
})
}
/**
* Gets all database elements that match the specified query.
*
* @param {string} query - A Mango query describing the object(s) to find.
* @return {Promise<Array<Object>>} A promise to an array containing all objects matching the query.
*
* @function
*/
async getByQuery (query) {
const response = await this.db.find(query)
return response.docs
}
/**
* Adds the specified document to the database.
*
* @param {string} document - The document to add to the database.
* @return {string} The GUID of the newly created document.
*
* @function
*/
async create (document) {
const response = await this.db.post(document)
return response.id
}
/**
* Updates the specified document in the database.
*
* @param {string} document - The document to update.
*
* @function
*/
async update (document) {
this.db.put(document)
}
/**
* Removes the specified document from the database.
*
* @param {string} document - The document to remove from the database.
*
* @function
*/
async delete (document) {
this.db.remove(document)
}
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ActivityService.html">ActivityService</a></li><li><a href="AreaService.html">AreaService</a></li><li><a href="PouchService.html">PouchService</a></li><li><a href="ProjectService.html">ProjectService</a></li><li><a href="TagService.html">TagService</a></li></ul><h3>Global</h3><ul><li><a href="global.html#compareArrayByName">compareArrayByName</a></li><li><a href="global.html#router">router</a></li><li><a href="global.html#routes">routes</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.6</a> on Sun Jan 24 2021 18:08:50 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>