forked from rykyky/rtkdb_test_api_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_functions.js
More file actions
54 lines (50 loc) · 1.57 KB
/
db_functions.js
File metadata and controls
54 lines (50 loc) · 1.57 KB
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
const r = require('rethinkdb');
module.exports.selectAll = (_,r,dbName, tableName, doc_Key_ID) =>{
r.db(dbName)
.table(tableName)
.run(_, function (err, result) {
if (err) return console.log(Object.assign({}, err));
res.end(JSON.stringify(result, null, 2));
})
};
module.exports.selectById = (_,r,dbName, tableName, doc_ID_Value) => {
r.db(dbName)
.table(tableName)
.get(doc_ID_Value)
.run(_, function (err, result) {
if (err) return console.log(Object.assign({}, err));
res.end(JSON.stringify(result, null, 2));
})
};
module.exports.selectByField = (_, r, dbName, tableName, doc_Field_Name) => {
r.db(dbName)
.table(tableName)
.get(doc_Field_Name)
.run(_, function (err, result) {
if (err) return console.log(Object.assign({}, err));
res.end(JSON.stringify(result, null, 2));
})
};
module.exports.insert = (_, r,dbName, tableName, data2insert) => {
r.db(dbName)
.table(tableName)
.insert(data2insert)
.run(_, function (err, result) {
if (err) return console.log(Object.assign({}, err));
res.end(JSON.stringify(result, null, 2));
});
};
module.exports.createDB = (_,r,dbName) => {
r.dbCreate(dbName)
.run(_, function (err, result) {
if (err) return console.log(Object.assign({}, err));
res.end(JSON.stringify(result, null, 2));
});
};
module.exports.createTable = (_,r,tableName) => {
r.dbCreate(tableName)
.run(_, function (err, result) {
if (err) return console.log(Object.assign({}, err));
res.end(JSON.stringify(result, null, 2));
});
};