-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (31 loc) · 954 Bytes
/
app.js
File metadata and controls
38 lines (31 loc) · 954 Bytes
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
const config = require('./dbConfig.js').postgreSql;
const display = require('./display.js');
const treeize = require('treeize');
//it returns a function so passign the configuration to it
let knex = require('knex')(config);
display.clear();
//select statement using promises
// let query = knex('book').select('title','rating');
let query = knex('book')
.join('author','author.id','=','book.author_id')
.select(
'author.firstname','author.lastname',
'book.title as books:title', 'book.rating as books:rating', 'book.id as books:id'
)
.where('author.id',1);
run(query, 'json');
function run(knexQuery, mode){
return knexQuery.then(function(rows){
let tree = new treeize();
tree.grow(rows);
let authors = tree.getData();
display.write(authors, mode);
})
.catch(function(err){
display.write(err);
})
.finally(function(){
display.write('done');
knex.destroy();
});
}