Exports mysql js sync method
See original GitHub issueHi, 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
const mysql = require("promise-mysql");
const config = require("../../config/local")
let conn
async function init() {
conn = await 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,
})
}
init()
exports = conn
the conn variable is undefined.
in other mysql models file I would like to continue using the promised base sql, such as
exports.findEventByUid = function(uid){
return conn.query(`
SELECT _id, uid FROM Event WHERE uid = ?
`, [uid])
}
any suggestion or solution?
Thanks for the great tool. 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Node.js Synchronous queries with MySQL - Stack Overflow
I know I am late to this party but I feel I can help people like me that needed a way to use...
Read more >How to Run Synchronous Queries using sync-sql Module in ...
Now open MySQL and create a database for example 'demo'. ... So this is how you can run synchronized SQL queries in node...
Read more >Node.js, MySQL and async/await - codeburst
It means that you have to wait for the results of a query, but while waiting, your program will continue to execute. For...
Read more >MySQL Connection With Node.js Using Sequelize and Express
exports = db; The user should not forget to summon the sync() method in the server.js. const app = express(); app.use(....); const db...
Read more >Nodejs tutorial: using async await with module.exports
Here's a quick standalone tutorial covering something that caused me a great deal of difficulty yesterday.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
Then when you want to use it, something like:
In this example connector would be the export from your first file
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.