I need a way to reject the pg-promise in this code:
db.tx(async t => {
var file = await t.one(`insert into ui.user_datasets_files (user_dataset_id,filename) values (${itemId},'${fileName}') RETURNING id`);
var data = rows.map(row => {
return {
user_dataset_id: itemId,
file_id: file.id,
json_data: JSON.stringify(row)
};
});
const insert = pgPromise.helpers.insert(data, dataset_data_columns);
return t.none(insert);
}).then(() => callback()).catch(err => callback(err));
this line takes long time and user can end the connection:
return t.none(insert);
so, i want a way to end the execution and make rollback inside this event:
req.on('close', function () {
promise.reject('Connection Closed');
});