i want to do multiple MySQL insertions in a specefic ordner for my server-client-application.
var con = createDatabaseConnection();
function createDatabaseConnection() {
return (mysql.createConnection({
host: // hostIp,
user: // user,
password: //pw,
database: //databasename
});
}
function writeFoo(fooObject) {
var sql = // prepare sql insert for fooObject;
con.query(sql, function (err) {
// ? Is inserted data ready to use ?
}
});
function writeBar(barObject) {
var sql = // prepare sql insert for barObject;
con.query(sql, function (err) {
// ? Is inserted data ready to use ?
});
});
// Both arrays containing an unpredictable amount of objects
var fooArray = [];
var barArray = [];
The crucial point is that I have to be absolutely sure, that the fooObjects in the fooArray are inserted before the barArray gets inserted. Because the SQL INSERT statement which is used in writeBar() contains a SELECT statement which has to find the data inserted in writeFoo().
And at any moment an event could happen (client sends data that needs to be inserted), that would need this functionality too.
The real situation is a bit more complex, but i think that's the main problem at the moment.