Support for DBRefs, eager ref fetching, and DB commands

19 views
Skip to first unread message

rrc7cz

unread,
May 30, 2011, 8:35:02 AM5/30/11
to congomongo-dev
I recently forked congomongo and added a couple lines to support DBRef
creation and eager fetching by the existing fns. I also added some
basic support for executing database commands. Figured somebody else
might have similar needs.

https://github.com/rcampbell/congomongo

I wasn't sure how Steve & co would want to support eager fetching, so
instead of modifying existing code I created a decorator like so:

(def eager-command (with-ref-fetching command))

or

(def eager-fetch (with-ref-fetching fetch))

etc, which decorates fetch et. al., walking the result (if :clojure)
and fetching any nested DBRefs, so:

{:_id #<ObjectId 4ddf94b2aec7cc2220d30cfb>,
:type "foo",
:user
#<DBRef { "$ref" : "users", "$id" : "4dde672daec7c9b294446ebd" }>,
:timestamp #<Date Fri May 27 14:10:26 CEST 2011>}}

becomes:

{:_id #<ObjectId 4ddf94b2aec7cc2220d30cfb>,
:type "foo",
:user
{:_id #<ObjectId 4dde672daec7c9b294446ebd>,
:email "m...@foo.com",
:password
"$2a$10$HubC/TN3fiJTY7h69WntUee1sPYiBC0jvkK311vC5fHajRhxgteU6",
:nickname "rrc7cz"},
:timestamp #<Date Fri May 27 14:10:26 CEST 2011>}}

without impacting existing fetch functionality.


Steve Purcell

unread,
May 30, 2011, 6:17:50 PM5/30/11
to congomo...@googlegroups.com
I rather like how the decorator looks, and I'd be happy to pull it
in. Any chance of a quick unit test by way of example usage?

-Steve

Robert Campbell

unread,
May 31, 2011, 7:07:42 AM5/31/11
to congomo...@googlegroups.com

Steve Purcell

unread,
May 31, 2011, 8:45:20 AM5/31/11
to congomo...@googlegroups.com
Great! Merged, thanks!

I should note that, while I'm often the first to respond to patches, I'm
not the only congomongo maintainer, and I'm open to giving commit access
to past contributors who have a vested interest in the project being
well-maintained.

-Steve

Reply all
Reply to author
Forward
0 new messages