mongodb/couchdb: use associate where possible.

db4
John Benediktsson 2012-07-20 09:37:54 -07:00
parent b656c8ef9e
commit 5afca2989c
4 changed files with 20 additions and 17 deletions

View File

@ -156,7 +156,7 @@ C: <db> db
<json-post-data> couch get db-url "_temp_view" append couch-post ;
: temp-view-map ( map -- results )
"map" H{ } clone [ set-at ] keep temp-view ;
"map" associate temp-view ;
: save-doc-as ( assoc id -- )
[ dup <json-post-data> ] dip id-url couch-put response-ok

View File

@ -1,6 +1,7 @@
USING: calendar math fry kernel assocs math.ranges bson.reader io.streams.byte-array
sequences formatting combinators namespaces io tools.time prettyprint io.encodings.binary
accessors words mongodb.driver strings math.parser bson.writer ;
accessors words mongodb.driver strings math.parser bson.writer
hashtables ;
FROM: mongodb.driver => find ;
FROM: memory => gc ;
@ -191,7 +192,7 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
drop
[ trial-size
collection-name
trial-size 2 / "x" H{ } clone [ set-at ] keep
trial-size 2 / "x" associate
'[ _ _ <query> 1 limit (find) ] times ] ;
: find-all ( quot -- quot: ( -- ) )

View File

@ -1,7 +1,7 @@
USING: accessors arrays assocs bson.constants classes classes.tuple
combinators continuations fry kernel mongodb.driver sequences strings
vectors words combinators.smart literals memoize slots constructors ;
vectors words combinators.smart literals memoize slots constructors
hashtables ;
IN: mongodb.tuple
@ -88,8 +88,8 @@ GENERIC: mdb-index-map ( tuple -- sequence )
: user-defined-key-index ( class -- assoc )
mdb-slot-map user-defined-key
[ drop [ "user-defined-key-index" 1 ] dip
H{ } clone [ set-at ] keep <tuple-index> t >>unique?
[ ] [ name>> ] bi H{ } clone [ set-at ] keep
associate <tuple-index> t >>unique?
[ ] [ name>> ] bi associate
] [ 2drop H{ } clone ] if ;

View File

@ -1,5 +1,7 @@
USING: accessors assocs classes.mixin classes.tuple
classes.tuple.parser compiler.units fry kernel sequences mongodb.driver
classes.tuple.parser compiler.units fry kernel sequences
hashtables
mongodb.driver
mongodb.msg mongodb.tuple.collection
mongodb.tuple.persistent mongodb.tuple.state strings ;
FROM: mongodb.driver => update delete find count ;
@ -45,7 +47,7 @@ DEFER: tuple>query
GENERIC: id-selector ( object -- selector )
M: toid id-selector
[ value>> ] [ key>> ] bi H{ } clone [ set-at ] keep ; inline
[ value>> ] [ key>> ] bi associate ; inline
M: mdb-persistent id-selector
>toid id-selector ;