-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdemo02.js
More file actions
57 lines (49 loc) · 1.39 KB
/
demo02.js
File metadata and controls
57 lines (49 loc) · 1.39 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
55
56
const config = require('./dbConfig').postgreSql;
const display = require('./display');
const knex = require('knex')(config);
display.clear();
const wil = {firstname: 'Williom', lastname: 'shakespear'};
const ed = {firstname:'edward', lastname:'maya'};
const dave = {firstname:'dave', lastname:'turner'};
const jack = {firstname:'jack', lastname:'sparrow'};
// deleteRecords();
// createRecords();
updateRecords();
function createRecords(){
knex.insert([wil,ed,dave,jack]).into('author').returning('id').debug(false).then(function(id){
console.log(id);
return knex('author').debug(false); //select * from authors
})
.then(function(authors){
display.write(authors,'pretty');
})
.finally(function(){
knex.destroy();
});
}
//delete code
function deleteRecords(){
knex('author').where("id", ">",4).del().debug(false).then(function(count){
console.log(count);
return knex('author').debug(false);
}).then(function(authors){
display.write(authors,'pretty');
}).finally(function(){
knex.destroy();
});
}
//update records
function updateRecords(){
knex('book').where('author_id',"=",1)
.update({rating:0}).debug(false)
.then(function(count){
console.log(count);
return knex('book').select("author_id","title","rating").debug(false);
})
.then(function(rows){
display.write(rows,'pretty');
})
.finally(function(){
knex.destroy();
});
}