I want to use clojure to build a web service with a RESTful API that exposes resources stored in a relational database (mysql in this case). I'd like to use a library that, given a specification of the db schema, would translate incoming requests to db queries, or korma constructs.
Examples might be:
GET /users?status=4
translates to something like:
SELECT * FROM `users` WHERE `status` = 4;
or:
PUT /users/12
would be:
UPDATE `users` SET ... WHERE `id` = 12
Is there anything out there that would facilitate this?
In your service, you can get a map that contains:
{:uri "/users" :query-params {:status 4}}
Or something similar, at least. From there, you could use either honey sql or the DSL in clojure.java.jdbc.
There's no library I know of that goes from request map to sql query directly, though really we're only talking about a few lines of code to do what you're looking for.
What you're asking for isn't flexible or extensible. What if you need to move a table to a different schema? What if the url should change? What should happen if someone puts in bad query params? How easy is it to expose a new table? etc.
There's too many application specific decisions for this to be reasonably accomplished in a library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With