Skip to content

Database Transactions 🤝

Compare
Choose a tag to compare
@swlkr swlkr released this 28 Mar 15:29
· 100 commits to master since this release

There's one huge thing that's been missing from the database side of things and that's database transactions, there wasn't an easy way to do it using coast's existing database functions until now!

Here's how it works:

(coast/transaction connection
  (coast/insert connection {:customer/first-name "Johnny" :customer/last-name "Appleseed"})
  (coast/insert connection {:customer/first-name "Cody", :customer/last-name "Coast"}))

And both of those will either succeed or the whole transaction will fail. There's a new parameter in every coast function, including: q, pluck, fetch, insert, update, and delete.

Thanks to transactions, insert and update now return the inserted/updated row across both sqlite and postgresql!

Delete still returns the number of deleted rows though.

There were a few other improvements, there's now a new fn that checks a request for the X-Requested-With header:

(let [request {:headers {"x-requested-with" "XMLHttpRequest"}}]
  (coast/xhr? request))

That's cool.

There was also one other improvement to parsing json parameters if the content-type is application/json regardless if the route is a "site" route or an "api" route.

🎉