1 | ## Classes
|
2 |
|
3 | <dl>
|
4 | <dt><a href="#Cursor">Cursor</a></dt>
|
5 | <dd></dd>
|
6 | <dt><a href="#Datastore">Datastore</a></dt>
|
7 | <dd></dd>
|
8 | </dl>
|
9 |
|
10 | <a name="Cursor"></a>
|
11 |
|
12 | ## Cursor
|
13 | **Kind**: global class
|
14 |
|
15 | * [Cursor](#Cursor)
|
16 | * [.sort()](#Cursor+sort) ⇒ [<code>Cursor</code>](#Cursor)
|
17 | * [.skip()](#Cursor+skip) ⇒ [<code>Cursor</code>](#Cursor)
|
18 | * [.limit()](#Cursor+limit) ⇒ [<code>Cursor</code>](#Cursor)
|
19 | * [.project()](#Cursor+project) ⇒ [<code>Cursor</code>](#Cursor)
|
20 | * [.exec()](#Cursor+exec) ⇒ <code>Promise.<Array.<Object>></code>
|
21 | * [.then(fulfilled, [rejected])](#Cursor+then) ⇒ <code>Promise</code>
|
22 | * [.catch(rejected)](#Cursor+catch) ⇒ <code>Promise</code>
|
23 |
|
24 | <a name="Cursor+sort"></a>
|
25 |
|
26 | ### cursor.sort() ⇒ [<code>Cursor</code>](#Cursor)
|
27 | Sort the queried documents.
|
28 |
|
29 | See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
30 |
|
31 | **Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
32 | <a name="Cursor+skip"></a>
|
33 |
|
34 | ### cursor.skip() ⇒ [<code>Cursor</code>](#Cursor)
|
35 | Skip some of the queried documents.
|
36 |
|
37 | See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
38 |
|
39 | **Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
40 | <a name="Cursor+limit"></a>
|
41 |
|
42 | ### cursor.limit() ⇒ [<code>Cursor</code>](#Cursor)
|
43 | Limit the queried documents.
|
44 |
|
45 | See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
46 |
|
47 | **Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
48 | <a name="Cursor+project"></a>
|
49 |
|
50 | ### cursor.project() ⇒ [<code>Cursor</code>](#Cursor)
|
51 | Set the document projection.
|
52 |
|
53 | See: https://github.com/louischatriot/nedb#projections
|
54 |
|
55 | **Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
56 | <a name="Cursor+exec"></a>
|
57 |
|
58 | ### cursor.exec() ⇒ <code>Promise.<Array.<Object>></code>
|
59 | Execute the cursor.
|
60 |
|
61 | Since the Cursor has a `then` and a `catch` method
|
62 | JavaScript identifies it as a thenable object
|
63 | thus you can await it in async functions.
|
64 |
|
65 | **Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
66 | **Example**
|
67 | ```js
|
68 | // in an async function
|
69 | await datastore.find(...)
|
70 | .sort(...)
|
71 | .limit(...)
|
72 | ```
|
73 | **Example**
|
74 | ```js
|
75 | // the previous is the same as:
|
76 | await datastore.find(...)
|
77 | .sort(...)
|
78 | .limit(...)
|
79 | .exec()
|
80 | ```
|
81 | <a name="Cursor+then"></a>
|
82 |
|
83 | ### cursor.then(fulfilled, [rejected]) ⇒ <code>Promise</code>
|
84 | Execute the cursor and set promise callbacks.
|
85 |
|
86 | For more information visit:
|
87 | https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
|
88 |
|
89 | **Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
90 | <table>
|
91 | <thead>
|
92 | <tr>
|
93 | <th>Param</th><th>Type</th>
|
94 | </tr>
|
95 | </thead>
|
96 | <tbody>
|
97 | <tr>
|
98 | <td>fulfilled</td><td><code>function</code></td>
|
99 | </tr><tr>
|
100 | <td>[rejected]</td><td><code>function</code></td>
|
101 | </tr> </tbody>
|
102 | </table>
|
103 |
|
104 | <a name="Cursor+catch"></a>
|
105 |
|
106 | ### cursor.catch(rejected) ⇒ <code>Promise</code>
|
107 | Execute the cursor and set promise error callback.
|
108 |
|
109 | For more information visit:
|
110 | https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
|
111 |
|
112 | **Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
113 | <table>
|
114 | <thead>
|
115 | <tr>
|
116 | <th>Param</th><th>Type</th>
|
117 | </tr>
|
118 | </thead>
|
119 | <tbody>
|
120 | <tr>
|
121 | <td>rejected</td><td><code>function</code></td>
|
122 | </tr> </tbody>
|
123 | </table>
|
124 |
|
125 | <a name="Datastore"></a>
|
126 |
|
127 | ## Datastore
|
128 | **Kind**: global class
|
129 | **Summary**: As of v2.0.0 the Datastore class extends node's built
|
130 | in EventEmitter class and implements each method as an event
|
131 | plus additional error events. It also inherits the `compaction.done`
|
132 | event from nedb but for consistency, in this library the event
|
133 | was renamed to `compactionDone`.
|
134 |
|
135 | All event callbacks will be passed the same type of values,
|
136 | the first being the datastore, then the operation result (if there is any)
|
137 | and then the arguments of the called method. (Check out the first example!)
|
138 |
|
139 | All events have a matching error event that goes by the name of `${method}Error`,
|
140 | for example `findError` or `loadError`. The callbacks of these events will receive
|
141 | the same parameters as the normal event handlers except that instead of the
|
142 | operation result there will be an operation error. (Check out the second example!)
|
143 |
|
144 | A generic `__error__` event is also available. This event will be emitted at any of
|
145 | the above error events. The callbacks of this event will receive the same parameters
|
146 | as the specific error event handlers except that there will be one more parameter
|
147 | passed between the datastore and the error object, that being the name of the method
|
148 | that failed. (Check out the third example!)
|
149 |
|
150 | * [Datastore](#Datastore)
|
151 | * [new Datastore([pathOrOptions])](#new_Datastore_new)
|
152 | * _instance_
|
153 | * [.load()](#Datastore+load) ⇒ <code>Promise.<undefined></code>
|
154 | * [.find([query], [projection])](#Datastore+find) ⇒ [<code>Cursor</code>](#Cursor)
|
155 | * [.findOne([query], [projection])](#Datastore+findOne) ⇒ [<code>Cursor</code>](#Cursor)
|
156 | * [.insert(docs)](#Datastore+insert) ⇒ <code>Promise.<(Object\|Array.<Object>)></code>
|
157 | * [.update(query, update, [options])](#Datastore+update) ⇒ <code>Promise.<(number\|Object\|Array.<Object>)></code>
|
158 | * [.remove([query], [options])](#Datastore+remove) ⇒ <code>Promise.<number></code>
|
159 | * [.count([query])](#Datastore+count) ⇒ [<code>Cursor</code>](#Cursor)
|
160 | * [.ensureIndex(options)](#Datastore+ensureIndex) ⇒ <code>Promise.<undefined></code>
|
161 | * [.removeIndex(field)](#Datastore+removeIndex) ⇒ <code>Promise.<undefined></code>
|
162 | * _static_
|
163 | * [.create([pathOrOptions])](#Datastore.create) ⇒ <code>Proxy.<static></code>
|
164 |
|
165 | <a name="new_Datastore_new"></a>
|
166 |
|
167 | ### new Datastore([pathOrOptions])
|
168 | Datastore constructor...
|
169 |
|
170 | You should use `Datastore.create(...)` instead
|
171 | of `new Datastore(...)`. With that you can access
|
172 | the original datastore's properties such as `datastore.persistence`.
|
173 |
|
174 | Create a Datastore instance.
|
175 |
|
176 | Note that the datastore will be created
|
177 | relative to `process.cwd()`
|
178 | (unless an absolute path was passed).
|
179 |
|
180 | It's basically the same as the original:
|
181 | https://github.com/louischatriot/nedb#creatingloading-a-database
|
182 |
|
183 | <table>
|
184 | <thead>
|
185 | <tr>
|
186 | <th>Param</th><th>Type</th>
|
187 | </tr>
|
188 | </thead>
|
189 | <tbody>
|
190 | <tr>
|
191 | <td>[pathOrOptions]</td><td><code>string</code> | <code>Object</code></td>
|
192 | </tr> </tbody>
|
193 | </table>
|
194 |
|
195 | **Example**
|
196 | ```js
|
197 | let datastore = Datastore.create()
|
198 | datastore.on('update', (datastore, result, query, update, options) => {
|
199 | })
|
200 | datastore.on('load', (datastore) => {
|
201 | // this event doesn't have a result
|
202 | })
|
203 | datastore.on('ensureIndex', (datastore, options) => {
|
204 | // this event doesn't have a result
|
205 | // but it has the options argument which will be passed to the
|
206 | // event handlers
|
207 | })
|
208 | datastore.on('compactionDone', (datastore) => {
|
209 | // inherited from nedb's compaction.done event
|
210 | })
|
211 | ```
|
212 | **Example**
|
213 | ```js
|
214 | let datastore = Datastore.create()
|
215 | datastore.on('updateError', (datastore, error, query, update, options) => {
|
216 | })
|
217 | datastore.on('loadError', (datastore, error) => {
|
218 | })
|
219 | datastore.on('ensureIndexError', (datastore, error, options) => {
|
220 | })
|
221 | ```
|
222 | **Example**
|
223 | ```js
|
224 | let datastore = Datastore.create()
|
225 | datastore.on('__error__', (datastore, event, error, ...args) => {
|
226 | // for example
|
227 | // datastore, 'find', error, [{ foo: 'bar' }, {}]
|
228 | })
|
229 | ```
|
230 | <a name="Datastore+load"></a>
|
231 |
|
232 | ### datastore.load() ⇒ <code>Promise.<undefined></code>
|
233 | Load the datastore.
|
234 |
|
235 | Note that you don't necessarily have to call
|
236 | this method to load the datastore as it will
|
237 | automatically be called and awaited on any
|
238 | operation issued against the datastore
|
239 | (i.e.: `find`, `findOne`, etc.).
|
240 |
|
241 | **Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
242 | <a name="Datastore+find"></a>
|
243 |
|
244 | ### datastore.find([query], [projection]) ⇒ [<code>Cursor</code>](#Cursor)
|
245 | Find documents that match a query.
|
246 |
|
247 | It's basically the same as the original:
|
248 | https://github.com/louischatriot/nedb#finding-documents
|
249 |
|
250 | There are differences minor in how the cursor works though.
|
251 |
|
252 | **Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
253 | <table>
|
254 | <thead>
|
255 | <tr>
|
256 | <th>Param</th><th>Type</th>
|
257 | </tr>
|
258 | </thead>
|
259 | <tbody>
|
260 | <tr>
|
261 | <td>[query]</td><td><code>Object</code></td>
|
262 | </tr><tr>
|
263 | <td>[projection]</td><td><code>Object</code></td>
|
264 | </tr> </tbody>
|
265 | </table>
|
266 |
|
267 | **Example**
|
268 | ```js
|
269 | datastore.find({ ... }).sort({ ... }).exec().then(...)
|
270 | ```
|
271 | **Example**
|
272 | ```js
|
273 | datastore.find({ ... }).sort({ ... }).then(...)
|
274 | ```
|
275 | **Example**
|
276 | ```js
|
277 | // in an async function
|
278 | await datastore.find({ ... }).sort({ ... })
|
279 | ```
|
280 | <a name="Datastore+findOne"></a>
|
281 |
|
282 | ### datastore.findOne([query], [projection]) ⇒ [<code>Cursor</code>](#Cursor)
|
283 | Find a document that matches a query.
|
284 |
|
285 | It's basically the same as the original:
|
286 | https://github.com/louischatriot/nedb#finding-documents
|
287 |
|
288 | **Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
289 | <table>
|
290 | <thead>
|
291 | <tr>
|
292 | <th>Param</th><th>Type</th>
|
293 | </tr>
|
294 | </thead>
|
295 | <tbody>
|
296 | <tr>
|
297 | <td>[query]</td><td><code>Object</code></td>
|
298 | </tr><tr>
|
299 | <td>[projection]</td><td><code>Object</code></td>
|
300 | </tr> </tbody>
|
301 | </table>
|
302 |
|
303 | **Example**
|
304 | ```js
|
305 | datastore.findOne({ ... }).then(...)
|
306 | ```
|
307 | **Example**
|
308 | ```js
|
309 | // in an async function
|
310 | await datastore.findOne({ ... }).sort({ ... })
|
311 | ```
|
312 | <a name="Datastore+insert"></a>
|
313 |
|
314 | ### datastore.insert(docs) ⇒ <code>Promise.<(Object\|Array.<Object>)></code>
|
315 | Insert a document or documents.
|
316 |
|
317 | It's basically the same as the original:
|
318 | https://github.com/louischatriot/nedb#inserting-documents
|
319 |
|
320 | **Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
321 | <table>
|
322 | <thead>
|
323 | <tr>
|
324 | <th>Param</th><th>Type</th>
|
325 | </tr>
|
326 | </thead>
|
327 | <tbody>
|
328 | <tr>
|
329 | <td>docs</td><td><code>Object</code> | <code>Array.<Object></code></td>
|
330 | </tr> </tbody>
|
331 | </table>
|
332 |
|
333 | <a name="Datastore+update"></a>
|
334 |
|
335 | ### datastore.update(query, update, [options]) ⇒ <code>Promise.<(number\|Object\|Array.<Object>)></code>
|
336 | Update documents that match a query.
|
337 |
|
338 | It's basically the same as the original:
|
339 | https://github.com/louischatriot/nedb#updating-documents
|
340 |
|
341 | If you set `options.returnUpdatedDocs`,
|
342 | the returned promise will resolve with
|
343 | an object (if `options.multi` is `false`) or
|
344 | with an array of objects.
|
345 |
|
346 | **Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
347 | <table>
|
348 | <thead>
|
349 | <tr>
|
350 | <th>Param</th><th>Type</th>
|
351 | </tr>
|
352 | </thead>
|
353 | <tbody>
|
354 | <tr>
|
355 | <td>query</td><td><code>Object</code></td>
|
356 | </tr><tr>
|
357 | <td>update</td><td><code>Object</code></td>
|
358 | </tr><tr>
|
359 | <td>[options]</td><td><code>Object</code></td>
|
360 | </tr> </tbody>
|
361 | </table>
|
362 |
|
363 | <a name="Datastore+remove"></a>
|
364 |
|
365 | ### datastore.remove([query], [options]) ⇒ <code>Promise.<number></code>
|
366 | Remove documents that match a query.
|
367 |
|
368 | It's basically the same as the original:
|
369 | https://github.com/louischatriot/nedb#removing-documents
|
370 |
|
371 | **Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
372 | <table>
|
373 | <thead>
|
374 | <tr>
|
375 | <th>Param</th><th>Type</th>
|
376 | </tr>
|
377 | </thead>
|
378 | <tbody>
|
379 | <tr>
|
380 | <td>[query]</td><td><code>Object</code></td>
|
381 | </tr><tr>
|
382 | <td>[options]</td><td><code>Object</code></td>
|
383 | </tr> </tbody>
|
384 | </table>
|
385 |
|
386 | <a name="Datastore+count"></a>
|
387 |
|
388 | ### datastore.count([query]) ⇒ [<code>Cursor</code>](#Cursor)
|
389 | Count documents that match a query.
|
390 |
|
391 | It's basically the same as the original:
|
392 | https://github.com/louischatriot/nedb#counting-documents
|
393 |
|
394 | **Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
395 | <table>
|
396 | <thead>
|
397 | <tr>
|
398 | <th>Param</th><th>Type</th>
|
399 | </tr>
|
400 | </thead>
|
401 | <tbody>
|
402 | <tr>
|
403 | <td>[query]</td><td><code>Object</code></td>
|
404 | </tr> </tbody>
|
405 | </table>
|
406 |
|
407 | **Example**
|
408 | ```js
|
409 | datastore.count({ ... }).limit(...).then(...)
|
410 | ```
|
411 | **Example**
|
412 | ```js
|
413 | // in an async function
|
414 | await datastore.count({ ... })
|
415 | // or
|
416 | await datastore.count({ ... }).sort(...).limit(...)
|
417 | ```
|
418 | <a name="Datastore+ensureIndex"></a>
|
419 |
|
420 | ### datastore.ensureIndex(options) ⇒ <code>Promise.<undefined></code>
|
421 | https://github.com/louischatriot/nedb#indexing
|
422 |
|
423 | **Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
424 | <table>
|
425 | <thead>
|
426 | <tr>
|
427 | <th>Param</th><th>Type</th>
|
428 | </tr>
|
429 | </thead>
|
430 | <tbody>
|
431 | <tr>
|
432 | <td>options</td><td><code>Object</code></td>
|
433 | </tr> </tbody>
|
434 | </table>
|
435 |
|
436 | <a name="Datastore+removeIndex"></a>
|
437 |
|
438 | ### datastore.removeIndex(field) ⇒ <code>Promise.<undefined></code>
|
439 | https://github.com/louischatriot/nedb#indexing
|
440 |
|
441 | **Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
442 | <table>
|
443 | <thead>
|
444 | <tr>
|
445 | <th>Param</th><th>Type</th>
|
446 | </tr>
|
447 | </thead>
|
448 | <tbody>
|
449 | <tr>
|
450 | <td>field</td><td><code>string</code></td>
|
451 | </tr> </tbody>
|
452 | </table>
|
453 |
|
454 | <a name="Datastore.create"></a>
|
455 |
|
456 | ### Datastore.create([pathOrOptions]) ⇒ <code>Proxy.<static></code>
|
457 | Create a database instance.
|
458 |
|
459 | Use this over `new Datastore(...)` to access
|
460 | original nedb datastore properties, such as
|
461 | `datastore.persistence`.
|
462 |
|
463 | Note that this method only creates the `Datastore`
|
464 | class instance, not the datastore file itself.
|
465 | The file will only be created once an operation
|
466 | is issued against the datastore or if you call
|
467 | the `load` instance method explicitly.
|
468 |
|
469 | The path (if specified) will be relative to `process.cwd()`
|
470 | (unless an absolute path was passed).
|
471 |
|
472 | For more information visit:
|
473 | https://github.com/louischatriot/nedb#creatingloading-a-database
|
474 |
|
475 | **Kind**: static method of [<code>Datastore</code>](#Datastore)
|
476 | <table>
|
477 | <thead>
|
478 | <tr>
|
479 | <th>Param</th><th>Type</th>
|
480 | </tr>
|
481 | </thead>
|
482 | <tbody>
|
483 | <tr>
|
484 | <td>[pathOrOptions]</td><td><code>string</code> | <code>Object</code></td>
|
485 | </tr> </tbody>
|
486 | </table>
|
487 |
|