How can i achive atomicity just like django orm in fastapi with sqlalchmey orm
Question:
How can i achive atomicity just like django orm in fastapi with sqlalchmey orm.
What i am trying to do is making a cron script which will delete data from s3 bucket and DB a lot of data. If some how s3 operation fails and it creates inconsistency or either case s3 pass and DB fails. So I want to achive atomicity like we have in django "with atomic transactions".
What i am trying to do is making a cron script which will delete data from s3 bucket and DB a lot of data.
Answers:
One simple approach would be this way,
def function_name(...):
try:
...
db.commit()
except:
db.rollback()
finally:
db.close()
How can i achive atomicity just like django orm in fastapi with sqlalchmey orm.
What i am trying to do is making a cron script which will delete data from s3 bucket and DB a lot of data. If some how s3 operation fails and it creates inconsistency or either case s3 pass and DB fails. So I want to achive atomicity like we have in django "with atomic transactions".
What i am trying to do is making a cron script which will delete data from s3 bucket and DB a lot of data.
One simple approach would be this way,
def function_name(...):
try:
...
db.commit()
except:
db.rollback()
finally:
db.close()