-
Notifications
You must be signed in to change notification settings - Fork 17
/
test.js
43 lines (36 loc) · 1.06 KB
/
test.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
/*
---
name: tools.js
description: <
This is a demonstration of how dbslayer.js can be used.
It takes three parameters from the SQL query, a host
author: [Guillermo Rauch](http://devthought.com)
...
*/
var sys = require('sys')
dbslayer = require('./dbslayer'),
sql = process.ARGV[2],
db = new dbslayer.Server();
if (!sql){
sys.puts('Please provide the SQL query');
return;
}
db.query(sql)
// on success
.addCallback(function(result){
sys.puts('-------------------------');
for (var i = 0, l = result.ROWS.length; i < l; i++){
sys.puts('Row ' + i + ': ' + result.ROWS[i].join(' '));
}
})
// on error :(
.addErrback(function(error, errno){
sys.puts('-------------------------');
sys.puts('MySQL error (' + (errno || '') + '): ' + error);
});
['stat', 'client_info', 'host_info', 'server_version', 'client_version'].forEach(function(command){
db[command]().addCallback(function(result){
sys.puts('-------------------------');
sys.puts(command.toUpperCase() + ' ' + result);
});
});