Fork me on GitHub

How can I do a transaction.begin at the start of a request and close/rollback at the end. ? For Ring I would just create a middleware.


@tawus you have a number of options. You can do a transaction begin at the start of your response function, since that is the only place mutation can/should occur. If you need read-consistency, you could alternatively provide a resource 'properties' function that will be called when your resource is being asked for its metadata, and start the transaction there, placing the transaction context in the yada context for later retrieval. You would have to catch mutation errors and do the commit/rollback yourself in the resource's response function. Nothing to stop you using a Ring middleware-like pattern in there.


Things are simpler in Ring, but that simplicity comes with a price - you can't do async. So if your database transaction requires I/O, you are blocking the request thread. Ring complects the handling of a HTTP request with the thread of execution - and that's a ok trade-off in many cases


Perhaps I mean to say things are easier in Ring, rather than simpler.


for anyone who's interested, he's an early-access link to a yada blog post I'm working on:


@malcolmsparks: Thanks for the reply. Wonderful work with yada!. I am a liberator user and the things you have done with yada is quite similar(and better) to what I had to do myself with liberator e.g. schema validation and coercion, async etc. I understand your point about async. I am using http-kit in my projects for async. But having it all together in yada can make life really easy.


@tawus: Thanks for the kind feedback. Yes, yada owes much to Liberator. I've used and contributed to Liberator a lot in the past (and even named it!) so yada is heavily influenced by Liberator's philosophy. The separation of routes and resources in particular is a key point from @ordnungswidrig which Liberator and yada both share, amongst other things. The key differences will be outlined in a future blog posy I'm working on