tmont / node-sql-generate

Automatically generates SQL definitions for use by the sql NodeJS module
24 stars 9 forks source link

rows.map error for mssql #7

Closed Aleyasen closed 6 years ago

Aleyasen commented 6 years ago

I ran the code using this command:

node-sql-generate --dsn "mssql://server=localhost;port=1433;user=myuser;password=mypassword;database=mydb"

but I got this error first:

/usr/local/lib/node_modules/sql-generate/index.js:312
            client = new db.Connection(mssqlDsn);
                     ^

TypeError: db.Connection is not a constructor
    at module.exports (/usr/local/lib/node_modules/sql-generate/index.js:312:13)
    at Object.<anonymous> (/usr/local/lib/node_modules/sql-generate/bin/node-sql-generate.js:77:1)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3

I fixed it by changing client = new db.Connection(mssqlDsn); to client = new db.ConnectionPool(mssqlDsn);

but after that I got this one:

// autogenerated by sql-generate v1.5.0 on Wed Sep 27 2017 18:42:23 GMT-0500 (CDT)

var sql = require('sql');

/usr/local/lib/node_modules/sql-generate/index.js:148
            callback(null, rows.map(function(row) {
                                ^

TypeError: rows.map is not a function
    at /usr/local/lib/node_modules/sql-generate/index.js:148:24
    at _query (/usr/local/lib/node_modules/mssql/lib/base.js:1255:9)
    at Request.tds.Request.err [as userCallback] (/usr/local/lib/node_modules/mssql/lib/tedious.js:620:15)
    at Request._this.callback (/usr/local/lib/node_modules/mssql/node_modules/tedious/lib/request.js:47:27)
    at Connection.message (/usr/local/lib/node_modules/mssql/node_modules/tedious/lib/connection.js:1401:27)
    at Connection.dispatchEvent (/usr/local/lib/node_modules/mssql/node_modules/tedious/lib/connection.js:687:45)
    at MessageIO.<anonymous> (/usr/local/lib/node_modules/mssql/node_modules/tedious/lib/connection.js:602:18)
    at emitNone (events.js:105:13)
    at MessageIO.emit (events.js:207:7)
    at ReadablePacketStream.<anonymous> (/usr/local/lib/node_modules/mssql/node_modules/tedious/lib/message-io.js:102:16)

Any thoughts are welcome.

my npm and node versions:

$ node --version
v8.4.0
$ npm --version
5.4.2
Aleyasen commented 6 years ago

The issue got fixed by these two changes: index.js:148 callback(null, rows.map(function(row) { to callback(null, rows.recordset.map(function(row) {

and index.js:196 results = results.map(function(col) { to results = results.recordset.map(function(col) {

tmont commented 6 years ago

What version of the mssql lib were you using? Might be helpful for others (I haven't used mssql on node myself).

Aleyasen commented 6 years ago

I am using mssql@4.0.4.

Thanks.

Aleyasen commented 6 years ago

btw, I just found out the changes are documented in mssql 4.x release note: https://github.com/patriksimek/node-mssql#3x-to-4x-changes