From 75c28ee62f0f9c0b3be372b0c41ddbcbf6921d35 Mon Sep 17 00:00:00 2001 From: Sascha Matzke Date: Tue, 3 Mar 2009 16:26:54 +0100 Subject: [PATCH] renamed some things moved _id and _mdb_ constants to bson vocab --- bson/constants/constants.factor | 1 + bson/writer/writer.factor | 14 +++++++------- mongodb/driver/driver.factor | 33 ++++++++++++++++----------------- mongodb/msg/msg.factor | 4 ++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/bson/constants/constants.factor b/bson/constants/constants.factor index 368374fb30..be9f9466b5 100644 --- a/bson/constants/constants.factor +++ b/bson/constants/constants.factor @@ -12,6 +12,7 @@ TUPLE: oid { a initial: 0 } { b initial: 0 } ; TUPLE: objref ns objid ; CONSTANT: MDB_OID_FIELD "_id" +CONSTANT: MDB_INTERNAL_FIELD "_mdb_" CONSTANT: T_EOO 0 CONSTANT: T_Double 1 diff --git a/bson/writer/writer.factor b/bson/writer/writer.factor index 55adb95b11..de764220be 100644 --- a/bson/writer/writer.factor +++ b/bson/writer/writer.factor @@ -3,7 +3,7 @@ USING: accessors assocs bson.constants byte-arrays fry io io.binary io.encodings.binary io.encodings.string io.encodings.utf8 io.streams.byte-array kernel math math.parser quotations sequences -serialize strings words ; +serialize strings words hashtables ; IN: bson.writer @@ -20,10 +20,10 @@ M: f bson-type? ( boolean -- type ) drop T_Boolean ; M: real bson-type? ( real -- type ) drop T_Double ; M: word bson-type? ( word -- type ) drop T_String ; M: tuple bson-type? ( tuple -- type ) drop T_Object ; -M: assoc bson-type? ( hashtable -- type ) drop T_Object ; +M: sequence bson-type? ( seq -- type ) drop T_Array ; M: string bson-type? ( string -- type ) drop T_String ; M: integer bson-type? ( integer -- type ) drop T_Integer ; -M: sequence bson-type? ( seq -- type ) drop T_Array ; +M: hashtable bson-type? ( hashtable -- type ) drop T_Object ; M: oid bson-type? ( word -- type ) drop T_OID ; M: objid bson-type? ( objid -- type ) drop T_Binary ; @@ -98,11 +98,11 @@ M: sequence bson-write ( array -- ) [ MDB_OID_FIELD ] dip at* [ [ MDB_OID_FIELD ] dip write-pair ] [ drop ] if ; inline -: oid-field? ( name -- boolean ) - MDB_OID_FIELD = ; inline +: skip-field? ( name -- boolean ) + { MDB_OID_FIELD MDB_INTERNAL_FIELD } member? ; inline -M: assoc bson-write ( hashtable -- ) - '[ _ [ write-oid ] [ [ over oid-field? [ 2drop ] [ write-pair ] if ] assoc-each ] bi ] +M: hashtable bson-write ( hashtable -- ) + '[ _ [ write-oid ] [ [ over skip-field? [ 2drop ] [ write-pair ] if ] assoc-each ] bi ] binary swap with-byte-writer [ length 5 + bson-write ] keep write diff --git a/mongodb/driver/driver.factor b/mongodb/driver/driver.factor index 6337452174..e9557a49ca 100644 --- a/mongodb/driver/driver.factor +++ b/mongodb/driver/driver.factor @@ -6,7 +6,7 @@ IN: mongodb.driver TUPLE: mdb-node master? inet ; -TUPLE: mdb name nodes collections ; +TUPLE: mdb-db name nodes collections ; TUPLE: mdb-cursor collection id return# ; @@ -23,9 +23,6 @@ CONSTRUCTOR: mdb-collection ( name -- collection ) ; CONSTANT: MDB-GENERAL-ERROR 1 -CONSTANT: MDB_OID "_id" -CONSTANT: MDB_PROPERTIES "_mdb_" - CONSTANT: PARTIAL? "partial?" CONSTANT: DIRTY? "dirty?" @@ -43,8 +40,10 @@ SYMBOL: mdb-socket-stream PRIVATE> -: mdb>> ( -- mdb ) - mdb get ; inline +SYMBOL: mdb-instance + +: mdb ( -- mdb ) + mdb-instance get ; inline : master>> ( mdb -- inet ) nodes>> [ t ] dip at inet>> ; @@ -53,7 +52,7 @@ PRIVATE> nodes>> [ f ] dip at inet>> ; : with-db ( mdb quot -- ... ) - [ [ '[ _ [ mdb set ] keep master>> + [ [ '[ _ [ mdb-instance set ] keep master>> [ remote-address set ] keep binary local-address set @@ -64,16 +63,16 @@ PRIVATE> > name>> "%s.system.indexes" sprintf ; inline + mdb name>> "%s.system.indexes" sprintf ; inline : namespaces-collection ( -- ns ) - mdb>> name>> "%s.system.namespaces" sprintf ; inline + mdb name>> "%s.system.namespaces" sprintf ; inline : cmd-collection ( -- ns ) - mdb>> name>> "%s.$cmd" sprintf ; inline + mdb name>> "%s.$cmd" sprintf ; inline : index-ns ( colname -- index-ns ) - [ mdb>> name>> ] dip "%s.%s" sprintf ; inline + [ mdb name>> ] dip "%s.%s" sprintf ; inline : ismaster-cmd ( node -- result ) binary "admin.$cmd" H{ { "ismaster" 1 } } @@ -103,11 +102,11 @@ PRIVATE> ] when* ; : verify-nodes ( -- ) - mdb>> nodes>> [ t ] dip at + mdb nodes>> [ t ] dip at check-nodes H{ } clone tuck '[ dup master?>> _ set-at ] each - [ mdb>> ] dip >>nodes drop ; + [ mdb ] dip >>nodes drop ; : send-message ( message -- ) [ mdb-stream>> ] dip '[ _ write-message ] with-stream* ; @@ -133,7 +132,7 @@ PRIVATE> check-nodes H{ } clone tuck '[ dup master?>> _ set-at ] each - H{ } clone mdb boa ; + H{ } clone mdb-db boa ; : create-collection ( name -- ) [ cmd-collection ] dip @@ -152,7 +151,7 @@ PRIVATE> '[ _ "%s contains invalid characters ( . $ ; )" sprintf throw ] when ; inline : (ensure-collection) ( collection -- ) - mdb>> collections>> dup keys length 0 = + mdb collections>> dup keys length 0 = [ load-collection-list [ [ "options" ] dip key? ] filter [ [ "name" ] dip at "." split second ] map @@ -166,11 +165,11 @@ MEMO: reserved-namespace? ( name -- ? ) PRIVATE> MEMO: ensure-collection ( collection -- fq-collection ) - "." split1 over mdb>> name>> = + "." split1 over mdb name>> = [ [ drop ] dip ] [ drop ] if [ ] [ reserved-namespace? ] bi [ [ (ensure-collection) ] keep ] unless - [ mdb>> name>> ] dip "%s.%s" sprintf ; inline + [ mdb name>> ] dip "%s.%s" sprintf ; inline : ( collection query -- mdb-query ) [ ensure-collection ] dip diff --git a/mongodb/msg/msg.factor b/mongodb/msg/msg.factor index 636e5e6755..7d1a8058b0 100644 --- a/mongodb/msg/msg.factor +++ b/mongodb/msg/msg.factor @@ -1,4 +1,4 @@ -USING: accessors assocs constructors kernel linked-assocs math +USING: accessors assocs hashtables constructors kernel linked-assocs math sequences strings ; IN: mongodb.msg @@ -86,7 +86,7 @@ M: sequence ( collection sequence -- mdb-insert-msg ) [ >>collection ] dip >>objects OP_Insert >>opcode ; -M: assoc ( collection assoc -- mdb-insert-msg ) +M: hashtable ( collection assoc -- mdb-insert-msg ) [ mdb-insert-msg new ] 2dip [ >>collection ] dip V{ } clone tuck push