I have a file uploader using Hasura
and AWS S3
. Is there a way for me to upload a file and insert into the database, and if one of the operations fail, rollback the change?
Here is some pseudocode to demonstrate what I mean:
query('... hasura query string ...').then(err => {
if (!err) {
s3.upload('my file').then(upload_err => {
if (!upload_err) {
// Commit database changes
} else {
// Rollback database changes
}
})
}
})
The only thing I can think of for doing this, is capture the insert id, then delete the record if the file upload fails. This doesn't seem like a good approach though.