Merge branch 'master' of git@github.com:x6j8x/mongo-factor-driver

Conflicts:
	mongodb/driver/driver.factor
db4
Sascha Matzke 2009-04-22 16:11:26 +02:00
commit e9551ab78e
1 changed files with 16 additions and 17 deletions

View File

@ -52,8 +52,6 @@ SYNTAX: r/ ( token -- mdbregexp )
[ MDB_OID_FIELD swap at ] keep
H{ } clone [ set-at ] keep ;
<PRIVATE
: make-cursor ( mdb-result-msg -- cursor/f )
dup cursor>> 0 >
[ [ cursor>> ] [ collection>> ] [ requested#>> ] tri <mdb-cursor> ]
@ -115,9 +113,7 @@ USE: tools.continuations
MEMO: reserved-namespace? ( name -- ? )
[ "$cmd" = ] [ "system" head? ] bi or ;
PRIVATE>
MEMO: ensure-collection ( collection -- fq-collection )
MEMO: check-collection ( collection -- fq-collection )
dup mdb-collection? [ name>> ] when
"." split1 over mdb-instance name>> =
[ nip ] [ drop ] if
@ -125,8 +121,9 @@ MEMO: ensure-collection ( collection -- fq-collection )
[ [ (ensure-collection) ] keep ] unless
[ mdb-instance name>> ] dip "%s.%s" sprintf ; inline
PRIVATE>
: <query> ( collection query -- mdb-query )
[ ensure-collection ] dip
<mdb-query-msg> ; inline
GENERIC# limit 1 ( mdb-query limit# -- mdb-query )
@ -163,19 +160,18 @@ GENERIC: explain. ( mdb-query -- )
M: mdb-query-msg explain.
t >>explain find nip . ;
GENERIC: find-one ( mdb-query -- result/f )
M: mdb-query-msg find-one
1 >>return# send-query-plain objects>>
dup empty? [ drop f ] [ first ] if ;
GENERIC: count ( collection selector -- result )
M: assoc count
[ "count" H{ } clone [ set-at ] keep ] dip
[ over [ "query" ] dip set-at ] when*
GENERIC: count ( mdb-query -- result )
M: mdb-query-msg count
[ collection>> "count" H{ } clone [ set-at ] keep ] keep
query>> [ over [ "query" ] dip set-at ] when*
[ cmd-collection ] dip <mdb-query-msg> find-one
[ check-ok ] keep '[ "n" _ at >fixnum ] [ f ] if ;
: lasterror ( -- error )
cmd-collection H{ { "getlasterror" 1 } } <mdb-query-msg>
find-one [ "err" ] dip at ;
@ -198,12 +194,12 @@ PRIVATE>
GENERIC: save ( collection assoc -- )
M: assoc save
[ ensure-collection ] dip
[ check-collection ] dip
<mdb-insert-msg> send-message-check-error ;
GENERIC: save-unsafe ( collection object -- )
M: assoc save-unsafe
[ ensure-collection ] dip
[ check-collection ] dip
<mdb-insert-msg> send-message ;
GENERIC: ensure-index ( collection name spec -- )
@ -224,7 +220,7 @@ M: assoc ensure-index
find-one drop ;
: <update> ( collection selector object -- update-msg )
[ ensure-collection ] 2dip <mdb-update-msg> ;
[ check-collection ] 2dip <mdb-update-msg> ;
: >upsert ( mdb-update-msg -- mdb-update-msg )
1 >>upsert? ;
@ -239,18 +235,21 @@ M: mdb-update-msg update-unsafe
GENERIC: delete ( collection selector -- )
M: assoc delete
[ ensure-collection ] dip
[ check-collection ] dip
<mdb-delete-msg> send-message-check-error ;
GENERIC: delete-unsafe ( collection selector -- )
M: assoc delete-unsafe
[ ensure-collection ] dip
[ check-collection ] dip
<mdb-delete-msg> send-message ;
: load-index-list ( -- index-list )
index-collection
H{ } clone <mdb-query-msg> find nip ;
: ensure-collection ( name -- )
check-collection drop ;
: drop-collection ( name -- )
[ cmd-collection ] dip
"drop" H{ } clone [ set-at ] keep