-
Notifications
You must be signed in to change notification settings - Fork 48
/
raw_connection.js
52 lines (44 loc) · 1.28 KB
/
raw_connection.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
var Redshift = require('../index.js');
var client = {
user: 'user',
database: 'database',
password: 'password',
port: 'port',
host: 'host'
};
var redshift = new Redshift(client, {rawConnection: true});
// using callbacks
// redshift.connect(function(err){ //create connection manually
// if(err) throw err;
// else{
// redshift.query('SELECT * FROM "Tags"', {raw: true}, function(err, data){ //query redshift
// if(err) throw err;
// else{
// console.log(data);
// redshift.close();
// }
// });
// }
// });
// using promises
// redshift.connect(function(err){ //create connection manually
// if(err) throw err;
// else{
// redshift.query('SELECT * FROM "Tags"', {raw: true})
// .then(function(data){ //query redshift
// console.log(data);
// redshift.close();
// }, function(err){
// throw err;
// });
// }
// });
// you can also skip connecting and closing manually by using the rawQuery function which creates a new redshift instance temporarily,
// connects to your db, makes a query, returns the data and disconnects from the database in one operation
redshift.rawQuery(`SELECT * FROM "Tags"`, {raw: true})
.then(function(data){
console.log(data);
})
.catch(function(err){
console.log(err);
});