0

I'm using module node-mssql(0.0.1 the latest version) to access SQL server. I want to use "select top x * from xxxx" so I use codes like:

var queryObj = new node_mssql.Query({
  host: 'x.x.x.x',
  port: 1433,
  username: 'xx',
  password: 'xxx',
  db: 'xxxxx'
});

queryObj.table(table);
queryObj.where(whereSql);
queryObj.limit(limit);
queryObj.order(order);
queryObj.select(function (data) {
    //success
    callback(data, res);
}, function (err, sql) {
    if (err) { //error
        console.log(err);
    }
});

But I got:

TypeError: queryObj.limit is not a function

error!

Since I can found

function Query(config) {
.....................
};
.....................
Query.prototype.limit = function(limit) {
  this.limit = limit;
  return this;
}; 
.....................................
module.exports = Query;       

in source codes of node-mssql, I don't understand why I got this error! Did I need to add somthing eles to make this function work?

BTW, can I add extra functions for the installed module? I try to add function:

Query.prototype.queryStr = function(queryStr) {
  this.queryStr = queryStr;
  return this;
};

But I got similar

TypeError: queryObj.queryStr is not a function

error..........

jones321
  • 55
  • 1
  • 10
  • 1
    You don't show where `queryObj` is coming from or what version of the module you're using ... – mscdex Dec 21 '16 at 02:00
  • Also, why not use a module like [`mssql`](https://github.com/patriksimek/node-mssql) instead, which is actively maintained? – mscdex Dec 21 '16 at 02:06
  • Thanks for the comment! I had added the mentioned missing part! I also had already tried other modules, howerver, I would still want to know the reason. Since I don't what the cause is which imply I might forgot some basic rules that I might cause some errors at some other places! – jones321 Dec 21 '16 at 02:20

0 Answers0