Closed sj82516 closed 7 years ago
Just to let you know I've seen this, but not had a chance to respond yet. I'll respond properly as soon as I can.
Would you wrap the mysql sync methods then export it ? I would like to try to contribute to the project by PR though I haven't PRed to open source before. Could you tell me about what you plan to do on this problem and the I can try to PR? Is that possible ? :P
It's more a change in how you're using it. I've not tested any of the following, but this should hopefully get the idea across:
const mysql = require("promise-mysql");
const config = require("../../config/local")
function init() {
return mysql.createPool({
host: config.model.mysql_psk_events.options.host,
user: config.model.mysql_psk_events.user,
password: config.model.mysql_psk_events.passwd,
database: config.model.mysql_psk_events.database,
multipleStatements: true,
connectionLimit: 20,
})
}
exports = init()
Then when you want to use it, something like:
exports.findEventByUid = function(uid){
const conn = await connector;
return conn.query(`
SELECT _id, uid FROM Event WHERE uid = ?
`, [uid])
}
In this example connector would be the export from your first file
@sj82516 Can you let me know if that worked so I can close the issue?
please close the issue. Thanks
@CodeFoodPixels we would need to do const conn = await connector
in every function that imports the connector.
It would be much more convenient if we have the option to import a synchronous version of .createPool()
.
Hi, Is that possible to expose sync methods of mysql js ? Because I would like to define connection in one js file and export the connection. However I cannot exports connection in async way. Here is my connection.js file
the conn variable is undefined.
in other mysql models file I would like to continue using the promised base sql, such as
any suggestion or solution?
Thanks for the great tool. :)