added regexp queries
parent
2a29d7fed4
commit
cd90702e39
|
@ -1,4 +1,4 @@
|
|||
USING: accessors kernel uuid ;
|
||||
USING: accessors kernel math parser sequences strings uuid ;
|
||||
|
||||
IN: bson.constants
|
||||
|
||||
|
@ -11,6 +11,12 @@ TUPLE: oid { a initial: 0 } { b initial: 0 } ;
|
|||
|
||||
TUPLE: objref ns objid ;
|
||||
|
||||
TUPLE: mdbregexp { regexp string } { options string } ;
|
||||
|
||||
: <mdbregexp> ( string -- mdbregexp )
|
||||
[ mdbregexp new ] dip >>regexp ;
|
||||
|
||||
|
||||
CONSTANT: MDB_OID_FIELD "_id"
|
||||
CONSTANT: MDB_INTERNAL_FIELD "_mdb_"
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ PREDICATE: bson-string < integer T_String = ;
|
|||
PREDICATE: bson-object < integer T_Object = ;
|
||||
PREDICATE: bson-array < integer T_Array = ;
|
||||
PREDICATE: bson-binary < integer T_Binary = ;
|
||||
PREDICATE: bson-regexp < integer T_Regexp = ;
|
||||
PREDICATE: bson-binary-bytes < integer T_Binary_Bytes = ;
|
||||
PREDICATE: bson-binary-function < integer T_Binary_Function = ;
|
||||
PREDICATE: bson-binary-uuid < integer T_Binary_UUID = ;
|
||||
|
@ -165,17 +166,21 @@ M: bson-double element-data-read ( type -- double )
|
|||
read-double ;
|
||||
|
||||
M: bson-boolean element-data-read ( type -- boolean )
|
||||
drop
|
||||
read-byte t = ;
|
||||
drop
|
||||
read-byte t = ;
|
||||
|
||||
M: bson-date element-data-read ( type -- timestamp )
|
||||
drop
|
||||
read-longlong millis>timestamp ;
|
||||
drop
|
||||
read-longlong millis>timestamp ;
|
||||
|
||||
M: bson-binary element-data-read ( type -- binary )
|
||||
drop
|
||||
read-int32 read-byte element-binary-read ;
|
||||
drop
|
||||
read-int32 read-byte element-binary-read ;
|
||||
|
||||
M: bson-regexp element-data-read ( type -- mdbregexp )
|
||||
drop mdbregexp new
|
||||
read-cstring >>regexp read-cstring >>options ;
|
||||
|
||||
M: bson-null element-data-read ( type -- bf )
|
||||
drop
|
||||
f ;
|
||||
|
|
|
@ -59,6 +59,7 @@ M: string bson-type? ( string -- type ) drop T_String ;
|
|||
M: integer bson-type? ( integer -- type ) drop T_Integer ;
|
||||
M: assoc bson-type? ( assoc -- type ) drop T_Object ;
|
||||
M: timestamp bson-type? ( timestamp -- type ) drop T_Date ;
|
||||
M: mdbregexp bson-type? ( regexp -- type ) drop T_Regexp ;
|
||||
|
||||
M: oid bson-type? ( word -- type ) drop T_OID ;
|
||||
M: objid bson-type? ( objid -- type ) drop T_Binary ;
|
||||
|
@ -122,12 +123,15 @@ M: objref bson-write ( objref -- )
|
|||
[ length write-int32 ] keep
|
||||
T_Binary_Custom write-byte
|
||||
write ;
|
||||
|
||||
M: mdbregexp bson-write ( regexp -- )
|
||||
[ regexp>> utf8 encode write-cstring ]
|
||||
[ options>> utf8 encode write-cstring ] bi ;
|
||||
|
||||
M: sequence bson-write ( array -- )
|
||||
'[ _ [ [ write-type ] dip number>string
|
||||
write-cstring bson-write ] each-index
|
||||
write-eoo
|
||||
] with-length-prefix ;
|
||||
write-eoo ] with-length-prefix ;
|
||||
|
||||
: write-oid ( assoc -- )
|
||||
[ MDB_OID_FIELD ] dip at*
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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
|
||||
arrays io memoize constructors sets strings uuid bson.writer ;
|
||||
arrays io memoize constructors sets strings uuid bson.writer bson.constants parser ;
|
||||
|
||||
IN: mongodb.driver
|
||||
|
||||
|
@ -38,8 +38,13 @@ SYMBOL: mdb-socket-stream
|
|||
: check-ok ( result -- ? )
|
||||
[ "ok" ] dip key? ; inline
|
||||
|
||||
: >mdbregexp ( value -- regexp )
|
||||
first <mdbregexp> ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: r/ \ / [ >mdbregexp ] parse-literal ; parsing
|
||||
|
||||
SYMBOL: mdb-instance
|
||||
|
||||
: mdb ( -- mdb )
|
||||
|
|
Loading…
Reference in New Issue