(Reposting to the main list from the committers list where I tested the waters)
Hi all, I've written a small library (http://github.com/Dridus/couchlift) that provides an integration to CouchDB using Lift JSON and Dispatch. Dispatch has an existing binding to Couch, but it uses its own JSON, and it's a bit thin. It's fairly uncomplicated -- it deals in JValues directly rather than some more "object database" like approach (perhaps baking in use of Lift JSON's excellent extraction capabilities), since that's the most general and it's pretty easy to just add extract/decompose calls as desired. I also opted against building any kind of design document DSL because it felt like too much structure. Here's some example code of use (adapted from the test suite): val http = new Http val database = new Database("my_database") // assumes localhost:5984 val design: JObject = ("language" -> "javascript") ~ ("views" -> (("all_students" -> ("map" -> "function(doc) { if (doc.type == 'student') { emit(null, doc); } }")) ~ ("students_by_age" -> ("map" -> "function(doc) { if (doc.type == 'student') { emit(doc.age, doc); } }")) ~ ("students_by_age_and_name" -> ("map" -> "function (doc) { if (doc.type == 'student') { emit([doc.age, doc.name], doc); } }")))) val docs: List[JObject] = (("type" -> "student") ~ ("name" -> "Alice") ~ ("age" -> 10)) :: (("type" -> "student") ~ ("name" -> "Bob") ~ ("age" -> 11)) :: (("type" -> "student") ~ ("name" -> "Charlie") ~ ("age" -> 11)) :: ... Nil http(database create) docs foreach { doc => http(database store doc) } // store figures out whether it's PUT or POST and where by looking at the doc http(database.design("my_design") <<<# design) // <<<# is direct PUT http(database query("my_design", "all_students", Query.limit(2))) http(database query("my_design", "students_by_age", Query.from(11), Query.to(12))) It's young, and I've only used it for a small personal project, so I'm sure there's improvements that could be made. There are a couple of specific issues/warts that I know about: - Uses exceptions more than Boxes, in one case it even open_!'s a Box to generate an exception. Though, this does fit better into the Dispatch style, and I find in practice it works okay because I tend to be wrapping http(database...) in tryo anyway, since dispatch reports non-success status codes as exceptions. - Multi-document fetch is not implemented. It should be doable via ComplexQueryParam (which is currently not populated) - Some of the query parameters are not unit tested. - toJObject is my (not so) secret shame. - no examples (but the test suite could probably be useful to teach in the interim) - no vscaladocs are generated by the POM I have, haven't yet figured out the maven magic to get that going I plan to do the following cleanup before I submit it: - Add PUT and POST aliases (or similar) as aliases for <<# and <<<# for people who prefer that. The current operators are named that way to match Dispatch. - Add record support (once I figure out how ;-) ) Thoughts? Comments on the library independent of the Lift context? -Ross -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.