added _id handling; the _id field must always be the first field in
a bson document. Handling it at this "low" level makes things easier in the layers abovedb4
parent
e21f367691
commit
22a891b483
|
@ -11,6 +11,8 @@ TUPLE: oid { a initial: 0 } { b initial: 0 } ;
|
|||
|
||||
TUPLE: objref ns objid ;
|
||||
|
||||
CONSTANT: MDB_OID_FIELD "_id"
|
||||
|
||||
CONSTANT: T_EOO 0
|
||||
CONSTANT: T_Double 1
|
||||
CONSTANT: T_Integer 16
|
||||
|
|
|
@ -93,9 +93,16 @@ M: sequence bson-write ( array -- )
|
|||
[ length 5 + bson-write ] keep
|
||||
write
|
||||
write-eoo ;
|
||||
|
||||
|
||||
: write-oid ( hashtable -- )
|
||||
[ MDB_OID_FIELD ] dip at*
|
||||
[ [ MDB_OID_FIELD ] dip write-pair ] [ drop ] if ; inline
|
||||
|
||||
: oid-field? ( name -- boolean )
|
||||
MDB_OID_FIELD = ; inline
|
||||
|
||||
M: assoc bson-write ( hashtable -- )
|
||||
'[ _ [ write-pair ] assoc-each ]
|
||||
'[ _ [ write-oid ] [ [ over oid-field? [ 2drop ] [ write-pair ] if ] assoc-each ] bi ]
|
||||
binary swap with-byte-writer
|
||||
[ length 5 + bson-write ] keep
|
||||
write
|
||||
|
|
|
@ -120,7 +120,7 @@ M: mdb-reply-op (read-message) ( msg-stub opcode -- message )
|
|||
read-longlong >>cursor
|
||||
read-int32 >>start#
|
||||
read-int32 [ >>returned# ] keep
|
||||
[ <linked-hash> stream>assoc drop ] accumulator [ times ] dip >>objects ;
|
||||
[ H{ } stream>assoc drop ] accumulator [ times ] dip >>objects ;
|
||||
|
||||
: read-header ( message -- message )
|
||||
read-int32 >>length
|
||||
|
@ -151,7 +151,7 @@ PRIVATE>
|
|||
write flush ; inline
|
||||
|
||||
: build-query-object ( query -- selector )
|
||||
[let | selector [ <linked-hash> ] |
|
||||
[let | selector [ H{ } clone ] |
|
||||
{ [ orderby>> [ "orderby" selector set-at ] when* ]
|
||||
[ explain>> [ "$explain" selector set-at ] when* ]
|
||||
[ hint>> [ "$hint" selector set-at ] when* ]
|
||||
|
|
Loading…
Reference in New Issue