Permalink
Browse files

[enhance] stdlib: Change orderby fields into list((string,int)).

  • Loading branch information...
1 parent c5d48f6 commit 7e70a4fbefb04a92afd485a0622b0a12ba44bc4b @nrs135 nrs135 committed Dec 9, 2011
@@ -234,7 +234,7 @@ MongoCollection = {{
{c with db={ c.db with ~fields }}
/** Set the "orderby" document in the collection. **/
- orderby(c:Mongo.collection('value), orderby:option(Bson.document)): Mongo.collection('value) =
+ orderby(c:Mongo.collection('value), orderby:list((string,int))): Mongo.collection('value) =
{c with db={ c.db with ~orderby }}
/** Set the "continueOnError" flag for all [insert] calls. **/
@@ -203,7 +203,7 @@ MongoCommands = {{
* are other elements in the reply.
**/
run_command_ll(m:Mongo.db, ns:string, command:Bson.document): Mongo.result =
- match MongoCursor.find_one(m, ns^".$cmd", command, {none}, {none}) with
+ match MongoCursor.find_one(m, ns^".$cmd", command, {none}, []) with
| {success=bson} -> MongoCommon.check_ok(bson)
| {~failure} -> {~failure}
@@ -454,19 +454,19 @@ MongoCommands = {{
* Query the "config.shards" database, gives a list of shards.
**/
findShards(m:Mongo.mongodb, query:Bson.document, limit:int): Mongo.results =
- MongoCursor.find_all(m.mongo, "config.shards", query, {none}, {none}, limit)
+ MongoCursor.find_all(m.mongo, "config.shards", query, {none}, [], limit)
/**
* Query the "config.databases" database, gives a list of shard information about databases.
**/
findDatabases(m:Mongo.mongodb, query:Bson.document, limit:int): Mongo.results =
- MongoCursor.find_all(m.mongo, "config.databases", query, {none}, {none}, limit)
+ MongoCursor.find_all(m.mongo, "config.databases", query, {none}, [], limit)
/**
* Query the "config.locks" database, gives information about the shard balancer.
**/
findBalancer(m:Mongo.mongodb, limit:int): Mongo.results =
- MongoCursor.find_all(m.mongo, "config.locks", [H.str("_id","balancer")], {none}, {none}, limit)
+ MongoCursor.find_all(m.mongo, "config.locks", [H.str("_id","balancer")], {none}, [], limit)
/**
* Low-level, set "config.settings" balancer value. Valid objects are "stopped" and "start/stop".
@@ -497,7 +497,7 @@ MongoCommands = {{
* Query the "config.chunks" database, gives a information about shard distribution.
**/
findChunks(m:Mongo.mongodb, query:Bson.document, limit:int): Mongo.results =
- MongoCursor.find_all(m.mongo, "config.chunks", query, {none}, {none}, limit)
+ MongoCursor.find_all(m.mongo, "config.chunks", query, {none}, [], limit)
/**
* Add a shard to a database.
@@ -563,9 +563,9 @@ MongoCommands = {{
| {some=0} | {none} -> {success=doc}//??failure
| _ ->
(match MongoCursor.find_all(m.mongo, "config.databases",
- [H.str("primary",shard)], {none}, {none}, 100) with
+ [H.str("primary",shard)], {none}, [], 100) with
| {success=dbs} ->
- (match MongoCursor.find_all(m.mongo, "config.shards", [], {none}, {none}, 100) with
+ (match MongoCursor.find_all(m.mongo, "config.shards", [], {none}, [], 100) with
| {success=[]} -> {failure={Error="No shards to move primary"}}
| {success=shards} ->
do println("dbs={Bson.to_pretty_list(dbs)}\nshards={Bson.to_pretty_list(shards)}")
@@ -65,7 +65,7 @@ type Mongo.mongodb = {
valname: string;
idxname: string;
fields: option(Bson.document);
- orderby: option(Bson.document);
+ orderby: list((string,int));
limit: int;
skip: int;
insert_flags: int;
@@ -224,7 +224,7 @@ MongoConnection = {{
db = {~mongo; ~name; bufsize=mongo.bufsize; ~addr; ~port; link_count=Mutable.make(1);
keyname="key"; valname="value"; idxname="index";
dbname="db"; collection="collection";
- fields={none}; orderby={none}; limit=0; skip=0;
+ fields={none}; orderby=[]; limit=0; skip=0;
insert_flags=0; update_flags=0; delete_flags=0; query_flags=0; index_flags=0;
}
do System.at_exit( ->
@@ -401,7 +401,7 @@ MongoConnection = {{
fields(db:Mongo.mongodb, fields:option(Bson.document)): Mongo.mongodb = { db with ~fields }
/** Set the "orderby" document on the given connection. **/
- orderby(db:Mongo.mongodb, orderby:option(Bson.document)): Mongo.mongodb = { db with ~orderby }
+ orderby(db:Mongo.mongodb, orderby:list((string,int))): Mongo.mongodb = { db with ~orderby }
/** Set the "continueOnError" flag for all [insert] calls. **/
continueOnError(db:Mongo.mongodb): Mongo.mongodb =
@@ -509,8 +509,8 @@ MongoConnection = {{
**/
query(m:Mongo.mongodb, query:Bson.document): option(Mongo.reply) =
query = (match m.orderby with
- | {some=orderby} -> [H.doc("$query",query), H.doc("$orderby",orderby)]
- | {none} -> query)
+ | [] -> query
+ | orderby -> [H.doc("$query",query), H.doc("$orderby",List.map(((f,o) -> H.i32(f,o)),orderby))])
MongoDriver.query(m.mongo, m.query_flags, "{m.dbname}.{m.collection}", m.skip, m.limit, query, m.fields)
/** Perform a get_more using inbuilt parameters **/
@@ -575,7 +575,7 @@ MongoConnection = {{
set_limit(c:Mongo.cursor, limit:int): Mongo.cursor = MongoCursor.set_limit(c,limit)
set_query(c:Mongo.cursor, query:option(Bson.document)): Mongo.cursor = MongoCursor.set_query(c,query)
set_fields(c:Mongo.cursor, fields:option(Bson.document)): Mongo.cursor = MongoCursor.set_fields(c,fields)
- set_orderby(c:Mongo.cursor, orderby:option(Bson.document)): Mongo.cursor = MongoCursor.set_orderby(c,orderby)
+ set_orderby(c:Mongo.cursor, orderby:list((string,int))): Mongo.cursor = MongoCursor.set_orderby(c,orderby)
tailable(c:Mongo.cursor): Mongo.cursor = MongoCursor.tailable(c)
op_query(c:Mongo.cursor): Mongo.cursor = MongoCursor.op_query(c)
get_more(c:Mongo.cursor): Mongo.cursor = MongoCursor.get_more(c)
@@ -58,7 +58,7 @@ type Mongo.cursor = {
limit : int;
query : option(Bson.document);
fields : option(Bson.document);
- orderby : option(Bson.document);
+ orderby : list((string,int));
query_sent : bool;
cid : Mongo.cursorID;
reply : option(Mongo.reply);
@@ -90,7 +90,7 @@ MongoCursor = {{
limit = 1;
query = {none};
fields = {none};
- orderby = {none};
+ orderby = [];
query_sent = {false};
cid = MongoCommon.null_cursorID(void);
reply = {none};
@@ -111,7 +111,7 @@ MongoCursor = {{
set_limit(c:Mongo.cursor, limit:int): Mongo.cursor = { c with ~limit }
set_query(c:Mongo.cursor, query:option(Bson.document)): Mongo.cursor = { c with ~query }
set_fields(c:Mongo.cursor, fields:option(Bson.document)): Mongo.cursor = { c with ~fields }
- set_orderby(c:Mongo.cursor, orderby:option(Bson.document)): Mongo.cursor = { c with ~orderby }
+ set_orderby(c:Mongo.cursor, orderby:list((string,int))): Mongo.cursor = { c with ~orderby }
tailable(c:Mongo.cursor): Mongo.cursor = { c with flags=Bitwise.lor(c.flags, MongoCommon.TailableCursorBit) }
@@ -146,8 +146,8 @@ MongoCursor = {{
if not(c.killed) && Option.is_some(c.query)
then
query = (match c.orderby with
- | {some=orderby} -> [H.doc("$query",Option.get(c.query)), H.doc("$orderby",orderby)]
- | {none} -> Option.get(c.query))
+ | [] -> Option.get(c.query)
+ | orderby -> [H.doc("$query",Option.get(c.query)), H.doc("$orderby",List.map(((f,o) -> H.i32(f,o)),orderby))])
reply(c,MongoDriver.query(c.mongo, c.flags, c.ns, c.skip, c.limit, query, c.fields),"op_query",{true})
else set_error(c,{Error=(if c.killed
then "MongoCursor.op_query: already killed"
@@ -304,7 +304,7 @@ MongoCursor = {{
* The cursor value is then returned, you can then use [MongoCursor.next] to
* scan along from there.
**/
- find(m:Mongo.db, ns:string, query:Bson.document, fields:option(Bson.document), orderby:option(Bson.document),
+ find(m:Mongo.db, ns:string, query:Bson.document, fields:option(Bson.document), orderby:list((string,int)),
limit:int, skip:int, flags:int): outcome(Mongo.cursor,Mongo.failure) =
c = init(m, ns)
c = set_query(c, {some=query})
@@ -342,7 +342,7 @@ MongoCursor = {{
* Creates and destroys a cursor.
**/
find_one(m:Mongo.db, ns:string,
- query:Bson.document, fields:option(Bson.document), orderby:option(Bson.document)): Mongo.result =
+ query:Bson.document, fields:option(Bson.document), orderby:list((string,int))): Mongo.result =
c = init(m, ns)
c = set_query(c, {some=query})
c = set_fields(c, fields)
@@ -363,7 +363,7 @@ MongoCursor = {{
* {b NOTE: reverses the order.}
**/
find_all(m:Mongo.db, ns:string, query:Bson.document,
- fields:option(Bson.document), orderby:option(Bson.document), limit:int): Mongo.results =
+ fields:option(Bson.document), orderby:list((string,int)), limit:int): Mongo.results =
cursor = init(m, ns)
cursor = set_query(cursor, {some=query})
cursor = set_fields(cursor, fields)

0 comments on commit 7e70a4f

Please sign in to comment.