-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnedbMethods.js
64 lines (53 loc) · 1.47 KB
/
nedbMethods.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
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
const db = require('nedb')
const slots = new db({filename : './slots'})
//slots.persistence.setAutocompactionInterval(10000)
slots.loadDatabase(err => err ? console.log('error') : console.log('Connected to nedb'))
function insertIntoDB(document) {
console.log('Inserting Dcument...')
return new Promise((resolve,reject) => {
slots.insert(document,(err,doc) => {
if(err)
reject(err)
else
resolve(doc)
})
})
}
function findInDB(query) {
console.log('Findng Dcument...')
return new Promise((resolve,reject) => {
slots.findOne(query,(err,doc) => {
if(err)
reject(err)
else
resolve(doc)
})
})
}
function updateDB(query,updateDoc) {
console.log('uodating doc ')
console.log(query)
console.log(updateDoc)
return new Promise((resolve,reject) => {
slots.update(query,updateDoc,{},(err,docNum)=>{
if(err)
reject(err)
else
resolve(docNum)
})
})
}
function deleteDocsInDB(query) {
return new Promise((resolve,reject) => {
slots.remove(query,{},(err,delNum) => {
if(err)
reject(err)
else
resolve(delNum)
})
})
}
module.exports.insertIntoDB = insertIntoDB
module.exports.findInDB = findInDB
module.exports.updateDB = updateDB
module.exports.deleteDocsInDB = deleteDocsInDB