Advertisement
Guest User

self-made solution

a guest
Apr 7th, 2012
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Select = function (){};
  2.  
  3. Select.prototype.launch = function (cstring,fn){
  4.                 client = new pg.Client(cstring);
  5.                 client.connect(function(err){
  6.                         if (err) return fn(err);
  7.                 });
  8.                 client.query("SELECT * FROM uuid_audit_table;",function(err,result){
  9.                         if (err) return fn(err);
  10.                         if (result.rows[0]){
  11.                                 return fn(null, result.rows[0]);
  12.                         } else {
  13.                                 return fn(null,"");
  14.                         }
  15.                 });
  16.  
  17. };
  18.  
  19. ### then called inside topic this way:
  20.  
  21.                 'we try to make a select': {
  22.                         topic: function () {
  23.                                 var select = new Select;
  24.                                 select.launch(connString,this.callback);
  25.                         },
  26.                         'we get some data': function(topic) {
  27.                                 //console.log(topic);
  28.                                 assert.isNotNull(topic[1]);
  29.                                 client.end();
  30.                         },
  31.                         'and no error': function(topic){
  32.                                 assert.isUndefined(topic[0]);
  33.                                 client.end();
  34.                         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement