Closed greenbigfrog closed 6 years ago
Hello, @greenbigfrog,
I suppose that should do the case:
db = DB.open(ENV["DATABASE_URL"])
db.transaction do |tx|
repo = Core::Repository.new(tx.connection, query_logger)
repo.insert(something)
repo.query(something)
end
You can read more about transactions here (though it's terribly documented). A working example of Crystal DB transaction could be found here.
Do not hesitate asking more questions or suggesting better implementation!
Thanks. That should do the job! For now I'll try to go plain SQL... Never a bad idea to know how to do it without help...
Since you seam to know your way around transactions I've still got a question for you. How can I send different log messages, depending on if a transaction was successfull or not?
db.transaction do |tx|
tx.exec(sth)
end
# if successfull log `tada` else log `error`
@greenbigfrog see this, whatever it means 😅
In a nutshell - begin
'n rescue
are youre friends here...
Hm. I guess I'll just have to do some testing... Thanks
@greenbigfrog please share your thoughts after testing!
Not sure if I'm missing it, or if core.cr doesn't support transactions.