bitemyapp / revise

RethinkDB client for Clojure
146 stars 8 forks source link

Plans for a `with-connection` kind of macro? #6

Closed john2x closed 10 years ago

cesarbp commented 10 years ago

I'm not sure. The driver at the moment is agnostic to the kind of connection management you want to use, which is why we don't try to provide connection pooling and the like. Although that might change in the future. A with-connection is pretty trivial to write. I'll just leave it open to see what Chris thinks.

(defmacro with-connection
  [binding-vec & body]
  `(let ~binding-vec
     (try (connect ~(binding-vec 0))
          (do ~@body)
          (finally
            (close ~(binding-vec 0))))))
bitemyapp commented 10 years ago

The way it's currently implemented is agnostic to specific use-cases but simple and amenable to anything you'd want to do.

Connection pooling isn't a thing for reasons specific to Revise, RethinkDB has their own connection pooling daemon, you definitely want to use that.

Dynamic scope in general is ick and doubly so in Clojure where it's not type-safe, composable, or escapable. That having been said it'd be pretty easy to make a partially applied function wrapped around run or run-async that references a dynamically scoped variable that would pull from the outer bindings.

I just don't think it's a good idea and not one I'd like to encourage. That having been said, I'm open to principled arguments for why it's valuable/necessary, if anybody thinks they can present one.

Perhaps the greater question is how to eliminate boiler-plate? My answer to that would be partial application and/or macros.

Concrete examples of the undesirable boilerplate would help to focus the conversation.

john2x commented 10 years ago

Understood.

@cesarbp thanks, this will do nicely for my purposes.

I'm not sure if I should close this or not?

bitemyapp commented 10 years ago

@john2x if your problem is solved and no further action is needed, yes.