forked from punkish/lana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
39 lines (31 loc) · 800 Bytes
/
db.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
33
34
35
36
37
38
39
// Load Chance
const Chance = require('chance');
// Instantiate Chance so it can be used
const chance = new Chance();
const path = require('path');
const dir = path.join(__dirname, 'data', 'readings');
const dbfile = path.join(dir, 'readings.db');
const Datastore = require('nedb');
const db = new Datastore({
filename: dbfile,
autoload: true
});
var docs = [];
for (let i=0, j=1000; i<j; i++) {
let doc = {
program: chance.word({length: 5}),
personnel: chance.natural(),
operations: chance.natural(),
investment: chance.natural()
};
docs.push(doc);
}
//console.log(docs);
db.insert(docs);
db.find({}, function (err, docs) {
if (err) {
console.log(err);
}
console.log('found all documents');
console.log(docs);
});