fixed bug in bson.writer which caused any field name "_id" to be written twice,

fixed lasterror in mongodb.driver
db4
Sascha Matzke 2009-03-05 07:01:12 +01:00
parent 208620336f
commit 87f0eeb282
3 changed files with 11 additions and 8 deletions

View File

@ -3,7 +3,7 @@
USING: accessors assocs bson.constants byte-arrays fry io io.binary USING: accessors assocs bson.constants byte-arrays fry io io.binary
io.encodings.binary io.encodings.string io.encodings.utf8 io.encodings.binary io.encodings.string io.encodings.utf8
io.streams.byte-array kernel math math.parser quotations sequences io.streams.byte-array kernel math math.parser quotations sequences
serialize strings words ; serialize strings words tools.hexdump ;
IN: bson.writer IN: bson.writer
@ -99,11 +99,13 @@ M: sequence bson-write ( array -- )
[ [ MDB_OID_FIELD ] dip write-pair ] [ drop ] if ; inline [ [ MDB_OID_FIELD ] dip write-pair ] [ drop ] if ; inline
: skip-field? ( name -- boolean ) : skip-field? ( name -- boolean )
{ MDB_OID_FIELD MDB_INTERNAL_FIELD } member? ; inline { "_id" "_mdb" } member? ; inline
M: assoc bson-write ( assoc -- ) M: assoc bson-write ( assoc -- )
'[ _ [ write-oid ] [ [ over skip-field? [ 2drop ] [ write-pair ] if ] assoc-each ] bi ] [ binary ] dip
binary swap with-byte-writer '[ _ [ write-oid ] keep
[ over skip-field? [ 2drop ] [ write-pair ] if ] assoc-each
] with-byte-writer
[ length 5 + bson-write ] keep [ length 5 + bson-write ] keep
write write
write-eoo ; write-eoo ;

View File

@ -1,6 +1,6 @@
USING: accessors assocs fry io.sockets kernel math mongodb.msg formatting linked-assocs destructors continuations USING: accessors assocs fry io.sockets kernel math mongodb.msg formatting linked-assocs destructors continuations
mongodb.operations namespaces sequences splitting math.parser io.encodings.binary combinators io.streams.duplex mongodb.operations namespaces sequences splitting math.parser io.encodings.binary combinators io.streams.duplex
arrays io memoize constructors sets strings ; arrays io memoize constructors sets strings uuid ;
IN: mongodb.driver IN: mongodb.driver
@ -231,7 +231,7 @@ M: assoc count
: lasterror ( -- error ) : lasterror ( -- error )
cmd-collection H{ { "getlasterror" 1 } } <mdb-query-msg> cmd-collection H{ { "getlasterror" 1 } } <mdb-query-msg>
find-one objects>> [ "err" ] at ; find-one objects>> first [ "err" ] dip at ;
GENERIC: validate ( collection -- ) GENERIC: validate ( collection -- )
M: string validate M: string validate
@ -262,6 +262,7 @@ M: assoc save-unsafe
GENERIC: ensure-index ( collection name spec -- ) GENERIC: ensure-index ( collection name spec -- )
M: assoc ensure-index M: assoc ensure-index
H{ } clone H{ } clone
[ [ uuid1 "_id" ] dip set-at ] keep
[ [ "key" ] dip set-at ] keep [ [ "key" ] dip set-at ] keep
[ [ "name" ] dip set-at ] keep [ [ "name" ] dip set-at ] keep
[ [ index-ns "ns" ] dip set-at ] keep [ [ index-ns "ns" ] dip set-at ] keep

View File

@ -1,7 +1,7 @@
USING: accessors fry io io.encodings.binary io.servers.connection USING: accessors fry io io.encodings.binary io.servers.connection
io.sockets io.streams.byte-array kernel math mongodb.msg classes formatting io.sockets io.streams.byte-array kernel math mongodb.msg classes formatting
mongodb.msg.private namespaces prettyprint tools.walker calendar calendar.format namespaces prettyprint tools.walker calendar calendar.format
json.writer ; json.writer mongodb.operations.private mongodb.operations ;
IN: mongodb.mmm IN: mongodb.mmm