Merge branch 'master' of http://factorcode.org/git/factor
commit
45f196214f
|
@ -59,21 +59,18 @@ CONSTANT: object-info T{ value-info f object full-interval }
|
|||
|
||||
: <value-info> ( -- info ) \ value-info new ;
|
||||
|
||||
: read-only-slots ( values class -- slots )
|
||||
all-slots
|
||||
[ read-only>> [ drop f ] unless ] 2map
|
||||
f prefix ;
|
||||
|
||||
DEFER: <literal-info>
|
||||
|
||||
: tuple-slot-infos ( tuple -- slots )
|
||||
[ tuple-slots ] [ class all-slots ] bi
|
||||
[ read-only>> [ <literal-info> ] [ drop f ] if ] 2map
|
||||
f prefix ;
|
||||
|
||||
: init-literal-info ( info -- info )
|
||||
dup literal>> class >>class
|
||||
dup literal>> dup real? [ [a,a] >>interval ] [
|
||||
[ [-inf,inf] >>interval ] dip
|
||||
dup tuple? [
|
||||
[ tuple-slots [ <literal-info> ] map ] [ class ] bi
|
||||
read-only-slots >>slots
|
||||
] [ drop ] if
|
||||
dup tuple? [ tuple-slot-infos >>slots ] [ drop ] if
|
||||
] if ; inline
|
||||
|
||||
: init-value-info ( info -- info )
|
||||
|
|
|
@ -9,7 +9,7 @@ compiler.tree.propagation.info compiler.tree.def-use
|
|||
compiler.tree.debugger compiler.tree.checker
|
||||
slots.private words hashtables classes assocs locals
|
||||
specialized-arrays.double system sorting math.libm
|
||||
math.intervals ;
|
||||
math.intervals quotations ;
|
||||
IN: compiler.tree.propagation.tests
|
||||
|
||||
[ V{ } ] [ [ ] final-classes ] unit-test
|
||||
|
@ -686,3 +686,8 @@ TUPLE: littledan-2 { from read-only } { to read-only } ;
|
|||
[ V{ 0 } ] [ [ { } length ] final-literals ] unit-test
|
||||
|
||||
[ V{ 1 } ] [ [ { } length 1+ f <array> length ] final-literals ] unit-test
|
||||
|
||||
! Mutable tuples with circularity should not cause problems
|
||||
TUPLE: circle me ;
|
||||
|
||||
[ ] [ circle new dup >>me 1quotation final-info drop ] unit-test
|
|
@ -30,8 +30,13 @@ UNION: fixed-length-sequence array byte-array string ;
|
|||
[ [ literal>> ] map ] dip prefix >tuple
|
||||
<literal-info> ;
|
||||
|
||||
: read-only-slots ( values class -- slots )
|
||||
all-slots
|
||||
[ read-only>> [ value-info ] [ drop f ] if ] 2map
|
||||
f prefix ;
|
||||
|
||||
: (propagate-tuple-constructor) ( values class -- info )
|
||||
[ [ value-info ] map ] dip [ read-only-slots ] keep
|
||||
[ read-only-slots ] keep
|
||||
over rest-slice [ dup [ literal?>> ] when ] all? [
|
||||
[ rest-slice ] dip fold-<tuple-boa>
|
||||
] [
|
||||
|
|
|
@ -6,11 +6,8 @@ io.encodings.utf8 io.streams.byte-array kernel math math.parser
|
|||
namespaces quotations sequences sequences.private serialize strings
|
||||
words combinators.short-circuit literals ;
|
||||
|
||||
|
||||
IN: bson.writer
|
||||
|
||||
#! Writes the object out to a byte-vector in BSON format
|
||||
|
||||
<PRIVATE
|
||||
|
||||
SYMBOL: shared-buffer
|
||||
|
@ -24,10 +21,9 @@ CONSTANT: INT64-SIZE 8
|
|||
[ 8192 <byte-vector> [ shared-buffer set ] keep ] unless* ; inline
|
||||
|
||||
: >le-stream ( x n -- )
|
||||
! >le write
|
||||
swap '[ _ swap nth-byte 0 B{ 0 }
|
||||
[ set-nth-unsafe ] keep write ] each
|
||||
; inline
|
||||
swap
|
||||
'[ _ swap nth-byte 0 B{ 0 }
|
||||
[ set-nth-unsafe ] keep write ] each ; inline
|
||||
|
||||
PRIVATE>
|
||||
|
||||
|
|
|
@ -8,10 +8,8 @@ HELP: <mdb-collection>
|
|||
{ "name" "name of the collection" }
|
||||
{ "collection" "mdb-collection instance" }
|
||||
}
|
||||
{ $description "Creates a new mdb-collection instance. Use this to create capped/limited collections. See also: " { $link mdb-collection } }
|
||||
{ $examples
|
||||
{ $example "! creates a mdb-collection instance capped to a maximum of 1000000 entries"
|
||||
"\"mycollection\" <mdb-collection> t >>capped 1000000 >>max" } } ;
|
||||
{ $examples { $unchecked-example "USING: mongodb.driver ;" "\"mycollection\" <mdb-collection> t >>capped 1000000 >>max" "" } }
|
||||
{ $description "Creates a new mdb-collection instance. Use this to create capped/limited collections." } ;
|
||||
|
||||
HELP: <mdb>
|
||||
{ $values
|
||||
|
@ -22,7 +20,7 @@ HELP: <mdb>
|
|||
}
|
||||
{ $description "Create a new mdb-db instance and automatically resolves master/slave information in a paired MongoDB setup." }
|
||||
{ $examples
|
||||
{ $example "\"db\" \"127.0.0.1\" 27017 <mdb>" } } ;
|
||||
{ $unchecked-example "USING: mongodb.driver ;" "\"db\" \"127.0.0.1\" 27017 <mdb>" "" } } ;
|
||||
|
||||
HELP: <query>
|
||||
{ $values
|
||||
|
@ -35,7 +33,7 @@ HELP: <query>
|
|||
"For more see: "
|
||||
{ $link with-db } }
|
||||
{ $examples
|
||||
{ $example "\"mycollection\" H{ } <query>" } } ;
|
||||
{ $unchecked-example "USING: mongodb.driver ;" "\"mycollection\" H{ } <query>" "" } } ;
|
||||
|
||||
HELP: <update>
|
||||
{ $values
|
||||
|
@ -118,22 +116,22 @@ HELP: drop-index
|
|||
|
||||
HELP: ensure-collection
|
||||
{ $values
|
||||
{ "collection" "a collection; e.g. mycollection " }
|
||||
{ "fq-collection" "full qualified collection name; e.g. db.mycollection" }
|
||||
{ "name" "a collection; e.g. mycollection " }
|
||||
}
|
||||
{ $description "ensures that the collection exists in the database and returns its full qualified name" } ;
|
||||
{ $description "ensures that the collection exists in the database" } ;
|
||||
|
||||
HELP: ensure-index
|
||||
{ $values
|
||||
{ "collection" "a collection" }
|
||||
{ "name" "index name" }
|
||||
{ "spec" "index spec" }
|
||||
{ "index-spec" "an index specification" }
|
||||
}
|
||||
{ $description "Ensures the existence of the given index. "
|
||||
"For more information on MongoDB indexes see: " { $url "http://www.mongodb.org/display/DOCS/Indexes" } }
|
||||
{ $examples
|
||||
{ $example "\"mycollection\" nameIdx [ \"name\" asc ] keyspec <index-spec> ensure-index" }
|
||||
{ $example "\"mycollection\" nameIdx [ \"name\" asc ] keyspec <index-spec> unique-index ensure-index" } } ;
|
||||
{ $unchecked-example "USING: mongodb.driver ;"
|
||||
"\"db\" \"127.0.0.1\" 27017 <mdb>"
|
||||
"[ \"mycollection\" nameIdx [ \"name\" asc ] keyspec <index-spec> ensure-index ] with-db" "" }
|
||||
{ $unchecked-example "USING: mongodb.driver ;"
|
||||
"\"db\" \"127.0.0.1\" 27017 <mdb>" "[ \"mycollection\" nameIdx [ \"name\" asc ] keyspec <index-spec> unique-index ensure-index ] with-db" "" } } ;
|
||||
|
||||
HELP: explain.
|
||||
{ $values
|
||||
|
@ -143,31 +141,35 @@ HELP: explain.
|
|||
|
||||
HELP: find
|
||||
{ $values
|
||||
{ "mdb-query" "a query" }
|
||||
{ "cursor" "a cursor (if there are more results) or f" }
|
||||
{ "result" "a sequences of objects" }
|
||||
{ "selector" "a mdb-query or mdb-cursor" }
|
||||
{ "mdb-cursor/f" "a cursor (if there are more results) or f" }
|
||||
{ "seq" "a sequences of objects" }
|
||||
}
|
||||
{ $description "executes the given query" }
|
||||
{ $examples
|
||||
{ $example "\"mycollection\" H{ { \"name\" \"Alfred\" } } <query> find " } } ;
|
||||
{ $unchecked-example "USING: mongodb.driver ;"
|
||||
"\"db\" \"127.0.0.1\" 27017 <mdb>"
|
||||
"[ \"mycollection\" H{ { \"name\" \"Alfred\" } } <query> find ] with-db" "" } } ;
|
||||
|
||||
HELP: find-one
|
||||
{ $values
|
||||
{ "mdb-query" "a query" }
|
||||
{ "result" "a single object or f" }
|
||||
{ "mdb-query-msg" "a query" }
|
||||
{ "result/f" "a single object or f" }
|
||||
}
|
||||
{ $description "Executes the query and returns one object at most" } ;
|
||||
|
||||
HELP: hint
|
||||
{ $values
|
||||
{ "mdb-query" "a query" }
|
||||
{ "mdb-query-msg" "a query" }
|
||||
{ "index-hint" "a hint to an index" }
|
||||
{ "mdb-query" "modified query object" }
|
||||
{ "mdb-query-msg" "modified query object" }
|
||||
}
|
||||
{ $description "Annotates the query with a hint to an index. "
|
||||
"For detailed information see: " { $url "http://www.mongodb.org/display/DOCS/Optimizing+Mongo+Performance#OptimizingMongoPerformance-Hint" } }
|
||||
{ $examples
|
||||
{ $example "\"mycollection\" H{ { \"name\" \"Alfred\" } { \"age\" 70 } } <query> H{ { \"name\" 1 } } hint find" } } ;
|
||||
{ $unchecked-example "USING: mongodb.driver ;"
|
||||
"\"db\" \"127.0.0.1\" 27017 <mdb>"
|
||||
"[ \"mycollection\" H{ { \"name\" \"Alfred\" } { \"age\" 70 } } <query> H{ { \"name\" 1 } } hint find ] with-db" "" } } ;
|
||||
|
||||
HELP: lasterror
|
||||
{ $values
|
||||
|
@ -179,13 +181,15 @@ HELP: lasterror
|
|||
|
||||
HELP: limit
|
||||
{ $values
|
||||
{ "mdb-query" "a query" }
|
||||
{ "mdb-query-msg" "a query" }
|
||||
{ "limit#" "number of objects that should be returned at most" }
|
||||
{ "mdb-query" "modified query object" }
|
||||
{ "mdb-query-msg" "modified query object" }
|
||||
}
|
||||
{ $description "Limits the number of returned objects to limit#" }
|
||||
{ $examples
|
||||
{ $example "\"mycollection\" H{ } <query> 10 limit find" } } ;
|
||||
{ $unchecked-example "USING: mongodb.driver ;"
|
||||
"\"db\" \"127.0.0.1\" 27017 <mdb>"
|
||||
"[ \"mycollection\" H{ } <query> 10 limit find ] with-db" "" } } ;
|
||||
|
||||
HELP: load-collection-list
|
||||
{ $values
|
||||
|
@ -202,23 +206,23 @@ HELP: load-index-list
|
|||
{ $description "Returns a list of all indexes that exist in the current database" } ;
|
||||
|
||||
HELP: mdb-collection
|
||||
{ $var-description "" } ;
|
||||
{ $var-description "MongoDB collection" } ;
|
||||
|
||||
HELP: mdb-cursor
|
||||
{ $var-description "" } ;
|
||||
{ $var-description "MongoDB cursor" } ;
|
||||
|
||||
HELP: mdb-error
|
||||
{ $values
|
||||
{ "msg" "error message" }
|
||||
}
|
||||
{ $description "" } ;
|
||||
{ $description "error class" } ;
|
||||
|
||||
HELP: r/
|
||||
{ $values
|
||||
{ "token" null }
|
||||
{ "mdbregexp" null }
|
||||
{ "token" "a regexp string" }
|
||||
{ "mdbregexp" "a mdbregexp tuple instance" }
|
||||
}
|
||||
{ $description "" } ;
|
||||
{ $description "creates a new mdbregexp instance" } ;
|
||||
|
||||
HELP: save
|
||||
{ $values
|
||||
|
@ -230,53 +234,53 @@ HELP: save
|
|||
|
||||
HELP: save-unsafe
|
||||
{ $values
|
||||
{ "collection" null }
|
||||
{ "object" object }
|
||||
{ "collection" "a collection" }
|
||||
{ "assoc" "object" }
|
||||
}
|
||||
{ $description "" } ;
|
||||
{ $description "Save the object to the given collection without automatic error check" } ;
|
||||
|
||||
HELP: skip
|
||||
{ $values
|
||||
{ "mdb-query" null }
|
||||
{ "skip#" null }
|
||||
{ "mdb-query" null }
|
||||
{ "mdb-query-msg" "a query message" }
|
||||
{ "skip#" "number of objects to skip" }
|
||||
{ "mdb-query-msg" "annotated query message" }
|
||||
}
|
||||
{ $description "" } ;
|
||||
{ $description "annotates a query message with a number of objects to skip when returning the results" } ;
|
||||
|
||||
HELP: sort
|
||||
{ $values
|
||||
{ "mdb-query" null }
|
||||
{ "quot" quotation }
|
||||
{ "mdb-query" null }
|
||||
{ "mdb-query-msg" "a query message" }
|
||||
{ "sort-quot" "a quotation with sort specifiers" }
|
||||
{ "mdb-query-msg" "annotated query message" }
|
||||
}
|
||||
{ $description "" } ;
|
||||
{ $description "annotates the query message for sort specifiers" } ;
|
||||
|
||||
HELP: update
|
||||
{ $values
|
||||
{ "mdb-update-msg" null }
|
||||
{ "mdb-update-msg" "a mdb-update message" }
|
||||
}
|
||||
{ $description "" } ;
|
||||
{ $description "performs an update" } ;
|
||||
|
||||
HELP: update-unsafe
|
||||
{ $values
|
||||
{ "mdb-update-msg" null }
|
||||
{ "mdb-update-msg" "a mdb-update message" }
|
||||
}
|
||||
{ $description "" } ;
|
||||
{ $description "performs an update without automatic error check" } ;
|
||||
|
||||
HELP: validate.
|
||||
{ $values
|
||||
{ "collection" null }
|
||||
{ "collection" "collection to validate" }
|
||||
}
|
||||
{ $description "" } ;
|
||||
{ $description "validates the collection" } ;
|
||||
|
||||
HELP: with-db
|
||||
{ $values
|
||||
{ "mdb" null }
|
||||
{ "quot" quotation }
|
||||
{ "mdb" "mdb instance" }
|
||||
{ "quot" "quotation to execute with the given mdb instance as context" }
|
||||
}
|
||||
{ $description "" } ;
|
||||
{ $description "executes a quotation with the given mdb instance in its context" } ;
|
||||
|
||||
ARTICLE: "mongodb.driver" "mongodb.driver"
|
||||
ARTICLE: "mongodb.driver" "MongoDB factor driver"
|
||||
{ $vocab-link "mongodb.driver" }
|
||||
;
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ PRIVATE>
|
|||
: <query> ( collection assoc -- mdb-query-msg )
|
||||
<mdb-query-msg> ; inline
|
||||
|
||||
GENERIC# limit 1 ( mdb-query-msg limit# -- mdb-query )
|
||||
GENERIC# limit 1 ( mdb-query-msg limit# -- mdb-query-msg )
|
||||
|
||||
M: mdb-query-msg limit
|
||||
>>return# ; inline
|
||||
|
@ -188,7 +188,7 @@ GENERIC# hint 1 ( mdb-query-msg index-hint -- mdb-query-msg )
|
|||
M: mdb-query-msg hint
|
||||
>>hint ;
|
||||
|
||||
GENERIC: find ( mdb-query-msg/mdb-cursor -- mdb-cursor seq )
|
||||
GENERIC: find ( selector -- mdb-cursor/f seq )
|
||||
|
||||
M: mdb-query-msg find
|
||||
fix-query-collection send-query ;
|
||||
|
@ -243,7 +243,7 @@ M: assoc save
|
|||
[ check-collection ] dip
|
||||
<mdb-insert-msg> send-message-check-error ;
|
||||
|
||||
GENERIC: save-unsafe ( collection object -- )
|
||||
GENERIC: save-unsafe ( collection assoc -- )
|
||||
M: assoc save-unsafe
|
||||
[ check-collection ] dip
|
||||
<mdb-insert-msg> send-message ;
|
||||
|
@ -266,7 +266,7 @@ M: index-spec ensure-index
|
|||
[ cmd-collection ] dip <mdb-query-msg>
|
||||
find-one drop ;
|
||||
|
||||
: <update> ( collection selector object -- update-msg )
|
||||
: <update> ( collection selector object -- mdb-update-msg )
|
||||
[ check-collection ] 2dip <mdb-update-msg> ;
|
||||
|
||||
: >upsert ( mdb-update-msg -- mdb-update-msg )
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
USING: accessors fry io io.encodings.binary io.servers.connection
|
||||
io.sockets io.streams.byte-array kernel math mongodb.msg classes formatting
|
||||
namespaces prettyprint tools.walker calendar calendar.format
|
||||
namespaces prettyprint tools.walker calendar calendar.format bson.writer.private
|
||||
json.writer mongodb.operations.private mongodb.operations ;
|
||||
|
||||
IN: mongodb.mmm
|
||||
|
|
|
@ -20,7 +20,7 @@ SYNTAX: MDBTUPLE:
|
|||
tuple-collection
|
||||
[ create-collection ]
|
||||
[ [ tuple-index-list ] keep
|
||||
'[ _ name>> swap [ name>> ] [ spec>> ] bi ensure-index ] each
|
||||
'[ _ name>> swap [ name>> ] [ spec>> ] bi <index-spec> ensure-index ] each
|
||||
] bi ;
|
||||
|
||||
: ensure-tables ( classes -- )
|
||||
|
@ -71,13 +71,12 @@ PRIVATE>
|
|||
tuple>selector <query> ;
|
||||
|
||||
: select-tuple ( tuple/query -- tuple/f )
|
||||
dup mdb-query-msg? [ ] [ tuple>query ] if
|
||||
dup mdb-query-msg? [ tuple>query ] unless
|
||||
find-one [ assoc>tuple ] [ f ] if* ;
|
||||
|
||||
: select-tuples ( tuple/query -- cursor tuples/f )
|
||||
dup mdb-query-msg? [ ] [ tuple>query ] if
|
||||
dup mdb-query-msg? [ tuple>query ] unless
|
||||
find [ assoc>tuple ] map ;
|
||||
|
||||
: count-tuples ( tuple/query -- n )
|
||||
dup mdb-query-msg? [ tuple>query ] unless
|
||||
[ collection>> ] [ query>> ] bi count ;
|
||||
dup mdb-query-msg? [ tuple>query ] unless count ;
|
||||
|
|
Loading…
Reference in New Issue