Permalink
Browse files

[cleanup] stdlib: Tidy up, remove debug statements and documentation …

…for cursor.opa.
  • Loading branch information...
1 parent 9eb005c commit 28fc00d066f413eae368780fadf8adc5352b5e37 @nrs135 nrs135 committed Nov 7, 2011
Showing with 111 additions and 98 deletions.
  1. +10 −10 stdlib/apis/mongo/MongoDb.opa
  2. +10 −10 stdlib/apis/mongo/commands.opa
  3. +90 −77 stdlib/apis/mongo/cursor.opa
  4. +1 −1 stdlib/apis/mongo/mongo.opa
@@ -1095,7 +1095,7 @@ type foreign('a,'b,'c,'d,'e) = {
type collection_cursor('a) = {
collection: collection('a);
- cursor: Cursor.cursor;
+ cursor: Mongo.cursor;
query: select('a);
ty: OpaType.ty;
ignore_incomplete: bool;
@@ -1199,11 +1199,11 @@ Collection : Collection = {{
find_one_doc(c:collection('value), select:select('value)): Mongo.result =
ns = c.db.dbname^"."^c.db.collection
- Cursor.find_one(c.db.mongo,ns,select,c.db.fields,c.db.orderby)
+ MongoCursor.find_one(c.db.mongo,ns,select,c.db.fields,c.db.orderby)
find_one_unsafe(c:collection('value), select:select('value), ignore_incomplete:bool): outcome('result,Mongo.failure) =
ns = c.db.dbname^"."^c.db.collection
- (match Cursor.find_one(c.db.mongo,ns,select,c.db.fields,c.db.orderby) with
+ (match MongoCursor.find_one(c.db.mongo,ns,select,c.db.fields,c.db.orderby) with
| {success=doc} ->
(match Bson.b2o_incomplete(doc, @typeval('result), ignore_incomplete) with
| {found=v} -> {success=(Magic.id(v):'result)}
@@ -1218,7 +1218,7 @@ Collection : Collection = {{
: outcome(collection_cursor('result),Mongo.failure) =
ns = c.db.dbname^"."^c.db.collection
//do println("query_unsafe:\n'value={OpaType.to_pretty(@typeval('value))}\n'result={OpaType.to_pretty(@typeval('result))}")
- match Cursor.find(c.db.mongo,ns,select,c.db.fields,c.db.orderby,c.db.limit,c.db.skip,c.db.query_flags) with
+ match MongoCursor.find(c.db.mongo,ns,select,c.db.fields,c.db.orderby,c.db.limit,c.db.skip,c.db.query_flags) with
| {success=cursor} ->
{success={collection=@unsafe_cast(c); ~cursor; query=@unsafe_cast(select); ty=@typeval('result); ~ignore_incomplete}}
| {~failure} -> {~failure}
@@ -1227,23 +1227,23 @@ Collection : Collection = {{
query_unsafe(c, select, false)
first(cc:collection_cursor('value)): outcome(collection_cursor('value),Mongo.failure) =
- _ = Cursor.reset(cc.cursor)
+ _ = MongoCursor.reset(cc.cursor)
query(cc.collection, cc.query)
next(cc:collection_cursor('value)): (collection_cursor('value),outcome('value,Mongo.failure)) =
- cursor = Cursor.next(cc.cursor)
- match Cursor.check_cursor_error(cursor) with
+ cursor = MongoCursor.next(cc.cursor)
+ match MongoCursor.check_cursor_error(cursor) with
| {success=doc} ->
//do println("next:\n doc={Bson.to_pretty(doc)}\n ty={OpaType.to_pretty(cc.ty)}")
(match Bson.b2o_incomplete(doc, cc.ty, cc.ignore_incomplete) with
| {found=v} -> ({cc with ~cursor},{success=(Magic.id(v):'value)})
| {not_found} -> ({cc with ~cursor},{failure={Error="Collection.next: not found"}})
| {incomplete} -> ({cc with ~cursor},{failure={Incomplete}}))
| {~failure} ->
- cursor = Cursor.reset(cursor)
+ cursor = MongoCursor.reset(cursor)
({cc with ~cursor},{~failure})
- has_more(cc:collection_cursor('value)): bool = Cursor.valid(cc.cursor)
+ has_more(cc:collection_cursor('value)): bool = MongoCursor.valid(cc.cursor)
find_all_unsafe(c:collection('value), select:select('value), ignore_incomplete:bool): outcome(list('result),Mongo.failure) =
//do println("find_all:\n 'value={OpaType.to_pretty(@typeval('value))}\n 'result={OpaType.to_pretty(@typeval('result))}")
@@ -1316,7 +1316,7 @@ Collection : Collection = {{
// TODO: map-reduce
- kill(cc:collection_cursor('value)): collection_cursor('value) = { cc with cursor=Cursor.reset(cc.cursor) }
+ kill(cc:collection_cursor('value)): collection_cursor('value) = { cc with cursor=MongoCursor.reset(cc.cursor) }
}}
@@ -156,7 +156,7 @@ Commands = {{
* are other elements in the reply.
**/
run_command(m:Mongo.db, ns:string, command:Bson.document): Mongo.result =
- match Cursor.find_one(m, ns^".$cmd", command, {none}, {none}) with
+ match MongoCursor.find_one(m, ns^".$cmd", command, {none}, {none}) with
| {success=bson} -> MongoDriver.check_ok(bson)
| {~failure} -> {~failure}
@@ -336,7 +336,7 @@ Commands = {{
(match query_opt with | {some=query} -> [H.doc("query",query)] | {none} -> [])])
match run_command(m, db, cmd) with
| {success=bson} ->
- //do println("Cursor.distinct: bson={Bson.to_pretty(bson)}")
+ //do println("MongoCursor.distinct: bson={Bson.to_pretty(bson)}")
// TODO: stats
(match Bson.find(bson,"values") with
| {some=[{name=k; value={Array=d}}]} -> {success=[H.arr(k,List.rev(d))]}
@@ -351,10 +351,10 @@ Commands = {{
[H.str("ns",coll), H.doc("key",key), H.code("$reduce",reduce), H.doc("initial",initial)],
(match cond_opt with | {some=cond} -> [H.doc("cond",cond)] | {none} -> [H.null("cond")]),
(match finalize_opt with | {some=finalize} -> [H.code("finalize",finalize)] | {none} -> [])]))]
- //do println("Cursor.group: group={Bson.to_pretty(group)}")
+ //do println("MongoCursor.group: group={Bson.to_pretty(group)}")
match run_command(m, db, group) with
| {success=bson} ->
- //do println("Cursor.group: bson={Bson.to_pretty(bson)}")
+ //do println("MongoCursor.group: bson={Bson.to_pretty(bson)}")
{success=bson}
| {~failure} -> {~failure}
@@ -382,17 +382,17 @@ Commands = {{
/**
* Query the config.shards database, gives a list of shards.
**/
- findShards(m:Mongo.db, query:Bson.document): Mongo.results = Cursor.find_all(m, "config.shards", query, 100)
+ findShards(m:Mongo.db, query:Bson.document): Mongo.results = MongoCursor.find_all(m, "config.shards", query, 100)
/**
* Query the config.databases database, gives a list of shard information about databases.
**/
- findDatabases(m:Mongo.db, query:Bson.document): Mongo.results = Cursor.find_all(m, "config.databases", query, 100)
+ findDatabases(m:Mongo.db, query:Bson.document): Mongo.results = MongoCursor.find_all(m, "config.databases", query, 100)
/**
* Query the config.locks database, gives information about the shard balancer.
**/
- findBalancer(m:Mongo.db): Mongo.results = Cursor.find_all(m, "config.locks", [H.str("_id","balancer")], 100)
+ findBalancer(m:Mongo.db): Mongo.results = MongoCursor.find_all(m, "config.locks", [H.str("_id","balancer")], 100)
/**
* Low-level, set config.settings balancer value. Valid objects are "stopped" and "start/stop".
@@ -421,7 +421,7 @@ Commands = {{
/**
* Query the config.chunks database, gives a information about shard distribution.
**/
- findChunks(m:Mongo.db, query:Bson.document): Mongo.results = Cursor.find_all(m, "config.chunks", query, 100)
+ findChunks(m:Mongo.db, query:Bson.document): Mongo.results = MongoCursor.find_all(m, "config.chunks", query, 100)
/**
* Add a shard to a database.
@@ -496,9 +496,9 @@ Commands = {{
(match Bson.dot_int(doc,"remaining.dbs") with
| {some=0} | {none} -> {success=doc}//??failure
| _ ->
- (match Cursor.find_all(m, "config.databases", [H.str("primary",shard)], 100) with
+ (match MongoCursor.find_all(m, "config.databases", [H.str("primary",shard)], 100) with
| {success=dbs} ->
- (match Cursor.find_all(m, "config.shards", [], 100) with
+ (match MongoCursor.find_all(m, "config.shards", [], 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)}")
Oops, something went wrong.

0 comments on commit 28fc00d

Please sign in to comment.