Answer the question
In order to leave comments, you need to log in
How to get data from a table right after inserting into it?
I am writing a simple application on node + mysql https://github.com/mysqljs/mysql
Everything seems to work, but there is one caveat:
When inserting several rows and getting data from a table after inserting - in some cases, some of the data may be missing (as like insert delayed or getting data before the inserts are done).
var pool = mysql.createPool(settings.mysql());
pool.queryPromise = function (sqlquery, params) {
return new Promise((resolve, reject) => {
this.getConnection(function (err, connection) {
// Use the connection
connection.query(sqlquery, params, function (error, results, fields) {
connection.release();
if (error) {
return reject(new Error(error));
} else {
return resolve(results);
}
});
});
});
}
//....
Promise.all(sheduleResult.map(elem => {
return pool.queryPromise('insert into table set ?', [elem]);
})).then( () => {
return pool.queryPromise('select * from table', [])
}).then( result => {
//тут работаем с результатом, так вот, там не всегда все вставленные строки
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question