chill117 / express-mysql-session

A MySQL session store for the express framework in node
MIT License
313 stars 106 forks source link

Promisse problem when utilizing mysql2. #130

Closed snow-sr closed 2 years ago

snow-sr commented 2 years ago

Hey there!

I'm with this problem right here:

Error: You have tried to call .then(), .catch(), or invoked await on the result of query that is not a promise, which is a programming error. Try calling con.promise().query(), or require('mysql2/promise') instead of 'mysql2' for a promise-compatible version of the query interface. To learn how to use async/await or Promises check out documentation at https://www.npmjs.com/package/mysql2#using-promise-wrapper, or the mysql2 documentation at https://github.com/sidorares/node-mysql2/tree/master/documentation/Promise-Wrapper.md at Query.then (/home/snowsr/coisas importantes /Workspaces/ecap/back (Node)/node_modules/mysql2/lib/commands/query.js:41:11) at MySQLStore.query (/home/snowsr/coisas importantes /Workspaces/ecap/back (Node)/node_modules/express-mysql-session/index.js:436:12) at MySQLStore.<anonymous> (/home/snowsr/coisas importantes /Workspaces/ecap/back (Node)/node_modules/express-mysql-session/index.js:133:9) at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)

And when utilizing the Const mysql = require('mysql2/promisses') I just received this error:

/home/snowsr/coisas importantes /Workspaces/ecap/back (Node)/node_modules/express-mysql-session/index.js:432 var promise = this.connection.query(sql, params, done); ^ TypeError: this.connection.query is not a function at MySQLStore.query (/home/snowsr/coisas importantes /Workspaces/ecap/back (Node)/node_modules/express-mysql-session/index.js:432:33) at MySQLStore.<anonymous> (/home/snowsr/coisas importantes /Workspaces/ecap/back (Node)/node_modules/express-mysql-session/index.js:133:9) at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)

Any solutions avaliable?

chill117 commented 2 years ago

Please post the code where you:

snow-sr commented 2 years ago

image

That's the code, it's exactly equal the example from NPM website.

image

chill117 commented 2 years ago

Change the following line:

var mysql2 = require('mysql2');

To:

var mysql2 = require('mysql2/promise');

I've updated the readme with a usage example - see Usage with mysql2

snow-sr commented 2 years ago

Wow! It worked, Thanks a lot for the help!