-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathreset.js
32 lines (27 loc) · 948 Bytes
/
reset.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
/*
Example of reset() API
---------------------
You can pass a JSON file path, or a JSON string or a JSON Object as parameter to this method.
If no data passed in the `data` parameter, the `jsonQ` Object instance will be reset to
previously initialized data.
*/
const jsonQ = require('../index.js');
let Q = new jsonQ(__dirname + '/data.json');
const users = Q.at('users')
.where('id', '=', 1)
.fetch();
console.log('-------- Printing Users ---------');
console.log(users);
// Resetting the instance to initial state
// because the previous at() query changed it internal state
Q = Q.reset();
const userVisits = Q.at('users.5.visits')
.where('year', '=', 2011)
.fetch();
console.log('-------- Printing User Visits ---------');
console.log(userVisits);
//You can reset the instance to a different set of Data
Q = Q.reset([1, 2, 5]);
const count = Q.count();
console.log('-------- Printing Count ---------');
console.log(count);