forked from raksix/rakdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
89 lines (82 loc) · 3.42 KB
/
index.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
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
const fs = require('fs');
const rakdb = {}
rakdb.yenidb = (payload) => {
fs.writeFile(payload + ".json", '[]', function (err, data) {
if (err) throw err;
})
}
rakdb.getir = (payload) => {
try {
const data = fs.readFileSync(payload + '.json', 'utf8')
return {
veri: JSON.parse(data),
ekle: function (payload2) {
try {
const data = fs.readFileSync(payload + ".json", "utf-8")
var oldData = JSON.parse(data)
let databro = [{ _id: [], data: [] }]
databro[0].data.push(payload2)
databro[0]._id.push(JSON.stringify(Date.now()))
oldData.push(databro)
fs.writeFile(payload + '.json', JSON.stringify(oldData), function (err, data) {
if (err) console.error(err)
return 'Başarılı'
})
return databro
} catch (err) {
console.error(err)
}
},
sil: function (params) {
try {
const data = fs.readFileSync(payload + ".json", "utf-8")
var oldData = JSON.parse(data)
const index = oldData.map(a => a[0]._id[0]).indexOf(params)
oldData.splice(index, 1)
if (index < 0) {
return 'Kardeşim bu bulunamadı'
}
fs.writeFile(payload + '.json', JSON.stringify(oldData), function (err, data) {
if (err) console.error(err)
})
return 'Başarılı Şekilde silindi';
} catch (err) {
console.error(err)
}
},
bul: function (params) {
try {
const data = fs.readFileSync(payload + ".json", "utf-8")
var oldData = JSON.parse(data)
const index = oldData.map(a => a[0]._id[0]).indexOf(params)
return {
veri: oldData[index][0],
degistir: function (param) {
try {
const array = []
array.push(param)
oldData[index][0].data = array
fs.writeFile(payload + '.json', JSON.stringify(oldData), function (err, data) {
if (err) console.error(err)
})
return oldData[index][0]
} catch (err) { }
},
ekle: function(param) {
oldData[index][0].data.push(param)
fs.writeFile(payload + '.json', JSON.stringify(oldData), function (err, data) {
if (err) console.error(err)
})
return oldData[index][0]
}
}
} catch (err) {
console.error(err)
}
},
}
} catch (err) {
console.error(err)
}
}
module.exports = rakdb;