Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[cleanup] runtime: Remove the old mongo driver(s)

  • Loading branch information...
commit e373aa66cb1f1d9ec70eb11a4f65c15d81d5dc01 1 parent b963b88
@BourgerieQuentin BourgerieQuentin authored
View
2  lib/plugins/mongo/_tags
@@ -1,2 +0,0 @@
-<bslMongo.ml>: with_mlstate_debug
-<mongo.opa_plugin>: use_libbase, use_opabsl_for_server, use_qmlcpsserver, use_qmlflatserver, use_appruntime, use_libnet
View
502 lib/plugins/mongo/bslMongo.ml
@@ -1,502 +0,0 @@
-(*
- Copyright © 2011, 2012 MLstate
-
- This file is part of Opa.
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*)
-
-module BslNativeLib = BslUtils
-
-(** TODO - plugins dependencies *)
-##property[mli]
-##extern-type continuation('a) = 'a QmlCpsServerLib.continuation
-##property[endmli]
-
-let opa_list_to_ocaml_list = BslUtils.opa_list_to_ocaml_list
-let ocaml_tuple_2 = BslUtils.ocaml_tuple_2
-let opa_tuple_2 = BslUtils.opa_tuple_2
-let create_outcome = BslUtils.create_outcome
-(** *****************************)
-
-module C = QmlCpsServerLib
-open C.Ops
-module FillbufString = Bson.FillbufString
-
-##opa-type Bson.document
-##opa-type Bson.element
-##extern-type bson_buf = Bson.buf
-##extern-type Mongo.mongo_buf = Mongo.mongo_buf
-##extern-type Mongo.cursorID = int64
-##extern-type Mongo.mailbox = (Buf.t * int ref)
-##extern-type Mongo.reply = (Buf.t * int * int)
-##extern-type Socket.connection = Scheduler.connection_info
-
-##module Bson
-
-exception Overflow of string
-let imax64 = Int64.of_int max_int
-let imin64 = Int64.of_int min_int
-let i64toi i64 =
- if i64 > imax64 || i64 < imin64 then raise (Overflow (Printf.sprintf "i64toi(%Ld)" i64));
- Int64.to_int i64
-let itoi64 = Int64.of_int
-#<Ifstatic:OCAML_WORD_SIZE 64>
-let i32toi = Int32.to_int
-let i32max = Int32.to_int Int32.max_int
-let i32min = Int32.to_int Int32.min_int
-let itoi32 i =
- if i > i32max || i < i32min then raise (Overflow (Printf.sprintf "itoi32(%d)" i));
- Int32.of_int i
-#<Else>
-let imax32 = Int32.of_int max_int
-let imin32 = Int32.of_int min_int
-let i32toi i32 =
- if i32 > imax32 || i32 < imin32 then raise (Overflow (Printf.sprintf "i32toi(%ld)" i32));
- Int32.to_int i32
-let itoi32 = Int32.of_int
-#<End>
-
-##register dump: int, string -> string
-let dump base s =
- let bb = Buffer.create 1024 in
- let bh = Buffer.create 1024 in
- let ba = Buffer.create 1024 in
- let len = String.length s in
- let m, n = len / base, len mod base in
- for i = 0 to m do
- let row = i * base in
- for j = 0 to (if i = m then n-1 else base-1) do
- let idx = i * base + j in
- let code = Char.code s.[idx] in
- Printf.bprintf bh "%02x " code;
- Printf.bprintf ba "%c" (if code >= 32 && code < 127 then s.[idx] else '.');
- if j = base-1 || (i = m && j = n-1)
- then
- (if base = 10
- then Printf.bprintf bb "%04d %-30s %-10s\n" row (Buffer.contents bh) (Buffer.contents ba)
- else Printf.bprintf bb "%04x %-48s %-16s\n" row (Buffer.contents bh) (Buffer.contents ba);
- Buffer.clear bh; Buffer.clear ba)
- done
- done;
- Buffer.contents bb
-
-##register new_oid: void -> string
-let new_oid () = Bson.Oid.gen ()
-
-##register oid_of_string: string -> string
-let oid_of_string = Bson.Oid.from_string
-
-##register oid_to_string: string -> string
-let oid_to_string = Bson.Oid.to_string
-
-let field_name = ServerLib.static_field_of_name "name"
-let field_value = ServerLib.static_field_of_name "value"
-
-let ocaml_element opa =
- let record = unwrap_opa_bson_element opa in
- let name = ServerLib.unsafe_dot record field_name in
- let value = ServerLib.unsafe_dot record field_value in
- (name, value)
-
-let serialize bsons b =
- let rec aux bsons =
- let rec aux3 r =
- match ServerLib.dot r BslNativeLib.field_hd with
- | None -> ()
- | Some element ->
- let (name, value) = ocaml_element element in
- ServerLib.fold_record
- (fun f value () ->
- let value = Obj.magic(value) in
- match ServerLib.name_of_field f with
- | Some "Double" -> Bson.Append.double b name (ServerLib.unwrap_float value)
- | Some "String" -> Bson.Append.string b name (ServerLib.unwrap_string value)
- | Some "Document" ->
- Bson.Append.start_object b name;
- aux (unwrap_opa_bson_document value);
- Bson.Append.finish_object b
- | Some "Array" ->
- Bson.Append.start_array b name;
- aux (unwrap_opa_bson_document value);
- Bson.Append.finish_array b
- | Some "Binary" ->
- let bin = Buffer.contents value in
- Bson.Append.binary b name Bson.st_bin_binary bin (String.length bin)
- | Some "ObjectID" -> Bson.Append.oid b name (ServerLib.unwrap_string value)
- | Some "Boolean" -> Bson.Append.bool b name (ServerLib.unwrap_bool value)
- | Some "Date" -> Bson.Append.date b name (itoi64 (ServerLib.unwrap_int value))
- | Some "Null" -> Bson.Append.null b name
- | Some "Min" -> Bson.Append.minkey b name
- | Some "Max" -> Bson.Append.maxkey b name
- | Some "Regexp" ->
- (match ocaml_tuple_2 value with
- | (regexp, regexp_opts) ->
- Bson.Append.regex b name (ServerLib.unwrap_string regexp) (ServerLib.unwrap_string regexp_opts))
- | Some "Code" -> Bson.Append.code b name (ServerLib.unwrap_string value)
- | Some "Symbol" -> Bson.Append.symbol b name (ServerLib.unwrap_string value)
- | Some "CodeScope" ->
- (match ocaml_tuple_2 value with
- | (code, scope) ->
- Bson.Append.start_codewscope b name code;
- aux scope;
- Bson.Append.finish_codewscope b code)
- | Some "Int32" -> Bson.Append.int b name (itoi32 (ServerLib.unwrap_int value))
- | Some "Timestamp" ->
- (match ocaml_tuple_2 value with
- | (i, t) ->
- Bson.Append.timestamp b name ((itoi32 (ServerLib.unwrap_int i)), (itoi32 (ServerLib.unwrap_int t))))
- | Some "Int64" -> Bson.Append.long b name (itoi64 (ServerLib.unwrap_int value))
- | Some str ->
- Printf.eprintf "Unknown code: %s\n%!" str;
- assert false
- | None ->
- assert false)
- value ();
- aux3 (ServerLib.unsafe_dot r BslNativeLib.field_tl)
- in
- aux3 bsons
- in
- aux (unwrap_opa_bson_document bsons)
-
-let field_fst = ServerLib.static_field_of_name "f1"
-let field_snd = ServerLib.static_field_of_name "f2"
-let field_hd = ServerLib.static_field_of_name "hd"
-let field_tl = ServerLib.static_field_of_name "tl"
-let field_nil = ServerLib.static_field_of_name "nil"
-let field_int32 = ServerLib.static_field_of_name "Int32"
-let field_realint32 = ServerLib.static_field_of_name "RealInt32"
-let field_int64 = ServerLib.static_field_of_name "Int64"
-let field_realint64 = ServerLib.static_field_of_name "RealInt64"
-let field_double = ServerLib.static_field_of_name "Double"
-let field_bool = ServerLib.static_field_of_name "Boolean"
-let field_string = ServerLib.static_field_of_name "String"
-let field_document = ServerLib.static_field_of_name "Document"
-let field_null = ServerLib.static_field_of_name "Null"
-let field_minkey = ServerLib.static_field_of_name "Min"
-let field_maxkey = ServerLib.static_field_of_name "Max"
-let field_array = ServerLib.static_field_of_name "Array"
-let field_binary = ServerLib.static_field_of_name "Binary"
-let field_objectid = ServerLib.static_field_of_name "ObjectID"
-let field_date = ServerLib.static_field_of_name "Date"
-let field_regexp = ServerLib.static_field_of_name "Regexp"
-let field_code = ServerLib.static_field_of_name "Code"
-let field_symbol = ServerLib.static_field_of_name "Symbol"
-let field_codescope = ServerLib.static_field_of_name "CodeScope"
-let field_timestamp = ServerLib.static_field_of_name "Timestamp"
-
-let shared_nil = ServerLib.make_simple_record field_nil
-let make_element name value =
- ServerLib.make_record
- (ServerLib.add_field
- (ServerLib.add_field ServerLib.empty_record_constructor field_name name)
- field_value value)
-let make_pair x y =
- ServerLib.make_record (ServerLib.add_field (ServerLib.add_field ServerLib.empty_record_constructor field_fst x) field_snd y)
-let make_cons hd tl =
- ServerLib.make_record (ServerLib.add_field (ServerLib.add_field ServerLib.empty_record_constructor field_hd hd) field_tl tl)
-
-let make_val fld n x =
- make_element n (ServerLib.make_record (ServerLib.add_field ServerLib.empty_record_constructor fld x))
-
-let make_null = make_val field_null
-let make_minkey = make_val field_minkey
-let make_maxkey = make_val field_maxkey
-let make_int32 = make_val field_int32
-let make_realint32 = make_val field_realint32
-let make_int64 = make_val field_int64
-let make_realint64 = make_val field_realint64
-let make_double = make_val field_double
-let make_bool n x = make_val field_bool n (ServerLib.wrap_bool x)
-let make_string = make_val field_string
-let make_document = make_val field_document
-let make_array = make_val field_array
-let make_binary n s =
- let x = Buffer.create (String.length s) in
- Buffer.add_string x s;
- make_val field_binary n x
-let make_objectid = make_val field_objectid
-let make_date = make_val field_date
-let make_regexp n r ro = make_val field_regexp n (make_pair r ro)
-let make_code = make_val field_code
-let make_symbol = make_val field_symbol
-let make_codescope n c s = make_val field_codescope n (make_pair c s)
-let make_timestamp n (i,t) = make_val field_timestamp n (make_pair (i32toi i) (i32toi t))
-
-let deserialize s =
- let i = Bson.IteratorSS.from_buffer s in
- let rec aux i =
- (function
- | c when c = Bson.el_eoo -> shared_nil
- | c when c = Bson.el_int ->
- let i32 = Bson.IteratorSS.int i in
- let e =
- try make_int32 (Bson.IteratorSS.key i) (i32toi i32)
- with (Overflow _) -> make_realint32 (Bson.IteratorSS.key i) i32
- in
- auxn e i
- | c when c = Bson.el_long ->
- let i64 = Bson.IteratorSS.long i in
- let e =
- try make_int64 (Bson.IteratorSS.key i) (i64toi i64)
- with (Overflow _) -> make_realint64 (Bson.IteratorSS.key i) i64
- in
- auxn e i
- | c when c = Bson.el_double -> let e = make_double (Bson.IteratorSS.key i) (Bson.IteratorSS.double i) in auxn e i
- | c when c = Bson.el_bool -> let e = make_bool (Bson.IteratorSS.key i) (Bson.IteratorSS.bool i) in auxn e i
- | c when c = Bson.el_string -> let e = make_string (Bson.IteratorSS.key i) (Bson.IteratorSS.string i) in auxn e i
- | c when c = Bson.el_object ->
- let key = Bson.IteratorSS.key i in
- let ii = Bson.IteratorSS.subiterator i in
- let bsons = aux ii (Bson.IteratorSS.next ii) in
- let e = make_document key bsons in auxn e i
- | c when c = Bson.el_array ->
- let key = Bson.IteratorSS.key i in
- let ii = Bson.IteratorSS.subiterator i in
- let bsons = aux ii (Bson.IteratorSS.next ii) in
- let e = make_array key bsons in auxn e i
- | c when c = Bson.el_bindata -> let e = make_binary (Bson.IteratorSS.key i) (Bson.IteratorSS.bin_data i) in auxn e i
- | c when c = Bson.el_oid -> let e = make_objectid (Bson.IteratorSS.key i) (Bson.IteratorSS.oid i) in auxn e i
- | c when c = Bson.el_date -> let e = make_date (Bson.IteratorSS.key i) (i64toi (Bson.IteratorSS.date i)) in auxn e i
- | c when c = Bson.el_null -> let e = make_null (Bson.IteratorSS.key i) ServerLib.void in auxn e i
- | c when c = Bson.el_minkey -> let e = make_minkey (Bson.IteratorSS.key i) ServerLib.void in auxn e i
- | c when c = Bson.el_maxkey -> let e = make_maxkey (Bson.IteratorSS.key i) ServerLib.void in auxn e i
- | c when c = Bson.el_regex ->
- let e = make_regexp (Bson.IteratorSS.key i) (Bson.IteratorSS.regex i) (Bson.IteratorSS.regex_opts i) in auxn e i
- | c when c = Bson.el_code -> let e = make_code (Bson.IteratorSS.key i) (Bson.IteratorSS.code i) in auxn e i
- | c when c = Bson.el_symbol -> let e = make_symbol (Bson.IteratorSS.key i) (Bson.IteratorSS.symbol i) in auxn e i
- | c when c = Bson.el_codewscope ->
- let key = Bson.IteratorSS.key i in
- let code = Bson.IteratorSS.code i in
- let b = Bson.IteratorSS.code_scope i in
- let ii = Bson.IteratorSS.init b in
- let scope = aux ii (Bson.IteratorSS.next ii) in
- let e = make_codescope key code scope in auxn e i
- | c when c = Bson.el_timestamp -> let e = make_timestamp (Bson.IteratorSS.key i) (Bson.IteratorSS.timestamp i) in auxn e i
- | c ->
- Printf.eprintf "Unknown Bson code: %c\n%!" c;
- assert false)
- and auxn e i = make_cons (wrap_opa_bson_document e) (aux i (Bson.IteratorSS.next i))
- in
- wrap_opa_bson_document (aux i (Bson.IteratorSS.next i))
-
-##endmodule
-
-##module Mongo
-
-let rid = ref(Random.int32(Int32.max_int))
-let nextrid() = let id = !rid in rid := Int32.add id 1l; id
-
-##register create: int -> Mongo.mongo_buf
-let create = Mongo.create
-
-##register insert: Mongo.mongo_buf, int, string, 'a -> void
-let insert m f ns (bson:'a) =
- let (bson:opa_bson_document) = Obj.magic bson in
- Mongo.start_insert m (nextrid()) f ns;
- Mongo.bson_init m;
- Bson.serialize bson m;
- Mongo.bson_finish m;
- Mongo.finish m
-
-##register insert_batch: Mongo.mongo_buf, int, string, opa[list('a)] -> void
-let insert_batch m f ns (bsons:'a) =
- let (bsons:opa_bson_document list) = Obj.magic (opa_list_to_ocaml_list (fun x -> x) bsons) in
- Mongo.start_insert m (nextrid()) f ns;
- List.iter (fun bson ->
- Mongo.bson_init m;
- Bson.serialize bson m;
- Mongo.bson_finish m) bsons;
- Mongo.finish m
-
-##register update: Mongo.mongo_buf, int, string, 'a, 'a -> void
-let update m flags ns selector update =
- let (selector:opa_bson_document) = Obj.magic selector in
- let (update:opa_bson_document) = Obj.magic update in
- Mongo.start_update m (nextrid()) flags ns;
- Mongo.bson_init m;
- Bson.serialize selector m;
- Mongo.bson_finish m;
- Mongo.bson_init m;
- Bson.serialize update m;
- Mongo.bson_finish m;
- Mongo.finish m
-
-##register query: Mongo.mongo_buf, int, string, int, int, 'a, option('a) -> void
-let query m flags ns numberToSkip numberToReturn query returnFieldSelector_opt =
- let (query:opa_bson_document) = Obj.magic query in
- let (returnFieldSelector_opt:opa_bson_document option) = Obj.magic returnFieldSelector_opt in
- Mongo.start_query m (nextrid()) flags ns numberToSkip numberToReturn;
- Mongo.bson_init m;
- Bson.serialize query m;
- Mongo.bson_finish m;
- (match returnFieldSelector_opt with
- | Some returnFieldSelector ->
- Mongo.bson_init m;
- Bson.serialize returnFieldSelector m;
- Mongo.bson_finish m
- | None -> ());
- Mongo.finish m
-
-##register set_query_flags: Mongo.mongo_buf, int -> void
-let set_query_flags m flags = Mongo.set_query_flags m flags
-
-##register get_opCode: Mongo.mongo_buf -> int
-let get_opCode m = Mongo.get_opCode m
-
-##register get_more: Mongo.mongo_buf, string, int, Mongo.cursorID -> void
-let get_more m ns numberToReturn cursorID =
- Mongo.start_getmore m (nextrid()) ns numberToReturn cursorID;
- Mongo.finish m
-
-##register delete: Mongo.mongo_buf, int, string, 'a -> void
-let delete m flags ns selector =
- let (selector:opa_bson_document) = Obj.magic selector in
- Mongo.start_delete m (nextrid()) flags ns;
- Mongo.bson_init m;
- Bson.serialize selector m;
- Mongo.bson_finish m;
- Mongo.finish m
-
-##register kill_cursors: Mongo.mongo_buf, opa[list('a)] -> void
-let kill_cursors m clist =
- let clist = Obj.magic clist in
- Mongo.start_kill_cursors m (nextrid()) (opa_list_to_ocaml_list (fun x -> x) clist);
- Mongo.finish m
-
-##register msg: Mongo.mongo_buf, string -> void
-let msg m msg =
- Mongo.start_msg m (nextrid()) msg;
- Mongo.finish m
-
-##register get: Mongo.mongo_buf -> string
-let get = Mongo.get
-
-##register export: Mongo.mongo_buf -> opa[tuple_2(string, int)]
-let export m =
- let (str, i) = Mongo.export m in
- opa_tuple_2 (ServerLib.wrap_string str, ServerLib.wrap_int i)
-
-##register import: string -> Mongo.mongo_buf
-let import = Mongo.import
-
-##register copy: Mongo.mongo_buf -> Mongo.mongo_buf
-let copy = Mongo.copy
-
-##register concat: Mongo.mongo_buf, Mongo.mongo_buf -> Mongo.mongo_buf
-let concat = Mongo.concat
-
-##register append: Mongo.mongo_buf, Mongo.mongo_buf -> void
-let append = Mongo.append
-
-##register length: Mongo.mongo_buf -> int
-let length = Mongo.length
-
-##register clip: Mongo.mongo_buf, int -> void
-let clip = Mongo.clip
-
-##register clear: Mongo.mongo_buf -> void
-let clear = Mongo.clear
-
-##register reset: Mongo.mongo_buf -> void
-let reset = Mongo.reset
-
-##register free: Mongo.mongo_buf -> void
-let free = Mongo.free
-
-##register new_mailbox: int -> Mongo.mailbox
-let new_mailbox size = (Mongo.get_buf ~hint:size (), ref 0)
-
-##register reset_mailbox: Mongo.mailbox -> void
-let reset_mailbox (b,_) = Mongo.free_buf b
-
-##register [cps-bypass] read_mongo : Socket.connection, int, Mongo.mailbox, continuation(outcome(Mongo.reply,string)) -> void
-let read_mongo conn timeout mailbox k =
- let timeout = Time.milliseconds timeout in
- HttpTools.fixed_stream_cps2_buf Scheduler.default conn mailbox 4 ()
- ~err_cont:(fun exn -> create_outcome (`failure (Printexc.to_string exn)) |> k)
- ~timeout
- (fun (b,s,l) ->
- if l < 4
- then create_outcome (`failure "BslMongo.Mongo.read_mongo insufficient data") |> k
- else
- let len = FillbufString.ldi32 (Buf.sub b s 4) 0 in
- HttpTools.fixed_stream_cps2_buf Scheduler.default conn mailbox (len-4) ()
- ~err_cont:(fun exn -> create_outcome (`failure (Printexc.to_string exn)) |> k)
- ~timeout
- (fun (b,s,l) ->
- if l < len - 4
- then create_outcome (`failure "BslMongo.Mongo.read_mongo insufficient data") |> k
- else create_outcome (`success (b,s,l)) |> k))
-
-##register export_reply: Mongo.reply -> string
-let export_reply (b,s,l) = Buf.sub b s l
-
-##register reply_messageLength : Mongo.reply -> int
-let reply_messageLength = Mongo.reply_messageLength
-
-##register reply_requestId : Mongo.reply -> int
-let reply_requestId = Mongo.reply_requestId
-
-##register reply_responseTo : Mongo.reply -> int
-let reply_responseTo = Mongo.reply_responseTo
-
-##register reply_opCode : Mongo.reply -> int
-let reply_opCode = Mongo.reply_opCode
-
-##register reply_responseFlags : Mongo.reply -> int
-let reply_responseFlags = Mongo.reply_responseFlags
-
-##register reply_cursorID : Mongo.reply -> Mongo.cursorID
-let reply_cursorID = Mongo.reply_cursorID
-
-##register reply_startingFrom : Mongo.reply -> int
-let reply_startingFrom = Mongo.reply_startingFrom
-
-##register reply_numberReturned : Mongo.reply -> int
-let reply_numberReturned = Mongo.reply_numberReturned
-
-##register reply_document : Mongo.reply, int -> option(Bson.document)
-let reply_document (b,s,l) n =
- match Mongo.reply_document_pos (b,s,l) n with
- | Some (pos, size) -> Some (Bson.deserialize (BaseStringSlice.import (b.Buf.str,pos,size)))
- | None -> None
-
-##register string_of_message : string -> string
-let string_of_message = Mongo.string_of_message_str
-
-##register string_of_message_reply : Mongo.reply -> string
-let string_of_message_reply = Mongo.string_of_message_reply
-
-##register null_cursorID : void -> Mongo.cursorID
-let null_cursorID () = 0L
-
-##register string_of_cursorID : Mongo.cursorID -> string
-let string_of_cursorID cid = Printf.sprintf "%016Lx" cid
-
-##register is_null_cursorID : Mongo.cursorID -> opa[bool]
-let is_null_cursorID cid = ServerLib.wrap_bool (cid = 0L)
-
-##register mongo_buf_requestId : Mongo.mongo_buf -> int
-let mongo_buf_requestId = Mongo.mongo_buf_requestId
-
-##register mongo_buf_refresh_requestId : Mongo.mongo_buf -> void
-let mongo_buf_refresh_requestId m = Mongo.mongo_buf_refresh_requestId m (nextrid())
-
-##register mongo_buf_responseTo : Mongo.mongo_buf -> int
-let mongo_buf_responseTo = Mongo.mongo_buf_responseTo
-
-##register encode_field : string -> string
-let encode_field field =
- Encodings.pc_encode_string
- (function '.' | '$' -> false | _ -> true)
- field
-
-##register decode_field : string -> string
-let decode_field = Encodings.pc_decode_string
-
-##endmodule
View
522 lib/plugins/mongo/bslMongo.nodejs
@@ -1,522 +0,0 @@
-var mongo = require('mongodb')
-var Admin = mongo.Admin;
-var BSON = mongo.BSONPure;
-var CheckMaster = mongo.CheckMaster;
-var Connection = mongo.Connection;
-var Cursor = mongo.Cursor;
-var Db = mongo.Db;
-var DbCommand = mongo.DbCommand;
-var GridStore = mongo.GridStore;
-var ReplSetServers = mongo.ReplSetServers;
-var Server = mongo.Server;
-var connect = mongo.connect;
-
-/** @externType NodeMongo.server */
-/** @externType NodeMongo.db */
-/** @externType NodeMongo.collection */
-/** @externType NodeBson.document */
-/** @externType NodeBson.value */
-/** @externType Mongo.reply */
-/** @externType binary */
-/** @opaType Bson.document */
-/** @opaType Bson.value */
-
-/** @externType int32 */
-/** @externType int64 */
-/** @opaType tuple_2('a, 'b) */
-/** @externType continuation('a) */
-/** @opaType list('a) */
-
-/** @module NodeBson */
-
- /**
- * @register { -> NodeBson.document}
- */
- function empty_document() {
- return {};
- }
-
- /**
- * @register { -> NodeBson.document}
- */
- function empty_array() {
- return [];
- }
-
- /**
- * @register {NodeBson.document, string, NodeBson.value -> void}
- */
- function add_element(doc, name, elt) {
- doc[name] = elt;
- return js_void;
- }
-
- /**
- * @register {float -> NodeBson.value}
- */
- function float_value(f) {
- return new mongo.Double(f);
- }
-
- /**
- * @register {int -> NodeBson.value}
- */
- function int_value(i) {
- return i;
- }
-
- /**
- * @register {string -> NodeBson.value}
- */
- function string_value(s) {
- return s;
- }
-
- /**
- * @register {bool -> NodeBson.value}
- */
- function bool_value(b) {
- return un_uniformize_bool(b);
- }
-
- /**
- * @register {int32 -> NodeBson.value}
- */
- function int32_value(i) {
- return i;
- }
-
- /**
- * @register {int, int -> NodeBson.value}
- */
- function timestamp_value(l, h) {
- return mongo.Timestamp(l, h);
- }
-
- /**
- * @register {int64 -> NodeBson.value}
- */
- function int64_value(i) {
- return mongo.Long(i[0], i[1]);
- }
-
- /**
- * @register {NodeBson.document -> NodeBson.value}
- */
- function document_value(d) {
- return d;
- }
-
- /**
- * @register {NodeBson.document -> NodeBson.value}
- */
- function array_value(a) {
- return a;
- }
-
- /**
- * @register {binary -> NodeBson.value}
- */
- function binary_value(b) {
- return new mongo.Binary(b.contents);
- }
-
- /**
- * @register {string -> NodeBson.value}
- */
- function object_id_value(s) {
- return new mongo.ObjectID(s);
- }
-
- /**
- * @register {int -> NodeBson.value}
- */
- function date_value(d) {
- return new Date(d);
- }
-
- /**
- * @register {-> NodeBson.value}
- */
- function null_value() {
- return null;
- }
-
- /**
- * @register {string, string -> NodeBson.value}
- */
- function regexp_value(p, f) {
- return new RegExp(p, f);
- }
-
- /**
- * @register {string -> NodeBson.value}
- */
- function code_value(c) {
- return new mongo.Code(c);
- }
-
- /**
- * @register {string -> NodeBson.value}
- */
- function symbol_value(s) {
- return new mongo.Symbol(s);
- }
-
- /**
- * @register {string, NodeBson.document -> NodeBson.value}
- */
- function code_scope_value(c, s) {
- return new mongo.Code(c, s);
- }
-
- /**
- * @register { -> NodeBson.value}
- */
- function min_value() {
- return new mongo.MinKey(); ;
- }
-
- /**
- * @register { -> NodeBson.value}
- */
- function max_value() {
- return new mongo.MaxKey(); ;
- }
-
-
- /**
- * @register {NodeBson.value -> Bson.value}
- */
- function to_value(x) {
- var t = typeof(x);
- switch(t){
- case 'string' : return {String : x};
- case 'number' : return {Int64 : x};
- case 'boolean': return {Boolean : x};
- case 'object' :
- if(x === null){
- return {Null : js_void};
- }
- var c = x.constructor;
- if(c === Array){
- return {Array : BslMongo_NodeBson_to_document(x)};
- } else if(c === Object){
- return {Document : BslMongo_NodeBson_to_document(x)};
- } else if(c === mongo.Double){
- return {Double : x.valueOf()};
- } else if(c === mongo.Timestamp) {
- return {Timestamp : {f1 : x.getHighBits(), f2 :x.getLowBits()}};
- } else if(c === mongo.Long){
- return {Int64 : [x.getHighBits(), x.getLowBits()]};
- } else if(c === mongo.Binary){
- return {Binary : binary_of_buffer(x.buffer)};
- } else if(c === mongo.ObjectID){
- return {ObjectID : x.toString()};
- } else if(c === mongo.Code){
- var c = x.code;
- for (var i in c.scope){
- var s = to_value(x.scope);
- return {CodeScope : {f1 : c, f2 : s}};
- }
- return {Code : c};
- } else if(c === mongo.Symbol){
- return {Symbol : x.valueOf()};
- } else if(c === mongo.MaxKey){
- return {Max : js_void};
- } else if(c === mongo.MinKey){
- return {Min : js_void};
- } else if(c === Date){
- return {Date : x.getTime()};
- } else {
- console.error("NodeBson.to_value", x, c);
- throw (new Error("Unknown mongo object"))
- }
- default :
- console.error("NodeBson.to_value", x, t);
- throw (new Error("Unknown typeof mongo object"))
- }
- }
-
- /**
- * @register {NodeBson.document -> Bson.document}
- */
- function to_document(doc) {
- var a = new Array();
- for (var name in doc){
- a.push({name:name, value: to_value(doc[name])});
- }
- return js2list(a);
- }
-
-/** @endModule */
-
-/** @module NodeMongo */
-
-// Note: the default default is false
-function getbool(b, dflt) {
- if (b === null || typeof b == 'undefined')
- return (typeof(dflt) === 'boolean') ? dflt : false;
- else if (typeof(b) === 'boolean')
- return b
- else
- return un_uniformize_bool(b)
-}
-
-var databaseTable;
-(function () {
- var opabsl = {};
- try {
- opabsl = require('opabsl.opp');
- } catch (e) {
- // If we can't require, we assume "static" linkage
- }
- var f = opabsl.SimpleTable || global.SimpleTable;
- databaseTable = new f();
-})();
-
-/**
- * @register {string, int, bool, int -> NodeMongo.server}
- */
-function server(host, port, auto_reconnect, poolSize) {
- return new Server(host, port, {auto_reconnect:auto_reconnect, poolSize:poolSize})
-}
-
-/**
- * @register {list(NodeMongo.server) -> NodeMongo.server}
- */
-function replset(servers) {
- return new ReplSetServers(list2js(servers))
-}
-
-/**
- * @register {NodeMongo.server, string, bool -> NodeMongo.db}
- */
-function db(server, dbname, slaveok) {
- return new Db(dbname, server, {slaveok:getbool(slaveok,false)})
-}
-
-/**
- * @register {NodeMongo.db, continuation(tuple_2(string, NodeMongo.db)) -> void}
- * @cpsBypass
- */
-function open(db, cont) {
- db.open(function(err, db) {
- return_(cont, {f1:(err === null || typeof err == 'undefined') ? "" : err.message, f2:db})
- });
- return;
-}
-
-/**
- * @register {NodeMongo.server, string, bool, \
- continuation(tuple_2(string, NodeMongo.db)) -> void}
- * @cpsBypass
- */
-function get_database(server, name, slaveok, k) {
- var barrier = databaseTable.get(name);
- if(barrier == null){
- var db = new Db(name, server, {slaveok: un_uniformize_bool(slaveok)});
- barrier = new Barrier("mongo_database:"+name);
- databaseTable.put(name, barrier);
- db.open(function(err, db){
- var result;
- if (err == null){
- result = {f1 : "", f2:db};
- } else {
- result = {f1 : err, f2:0};
- }
- barrier.release(result);
- })
- }
- barrier.wait(k);
- return;
-}
-
-/**
- * @register {NodeMongo.db, continuation(string) -> void}
- * @cpsBypass
- */
-function close(db, cont) {
- db.close(false, function (err, result) {
- return_(cont, (err === null || typeof err == 'undefined') ? "" : err.message);
- });
- return;
-}
-
-/**
- * @register {NodeMongo.db, string, continuation(tuple_2(string, NodeMongo.collection)) -> void}
- * @cpsBypass
- */
-function collection(db, cname, cont) {
- db.collection(cname,
- function(err, collection) {
- if (err === null || typeof err == 'undefined') {
- return_(cont, {f1: "", f2:collection})
- }else{
- return_(cont, {f1: err.message, f2:0})
- }
- });
- return;
-}
-
-/**
- * @register {NodeMongo.collection, int, int, NodeBson.document, \
- opa[option(NodeBson.document)], \
- continuation(tuple_2(string,Mongo.reply)) -> void}
- * @cpsBypass
- */
-function query(collection, skip, limit, query, fields_opt, cont) {
- var opts = {skip:skip, limit:limit};
- var fields = option2js(fields_opt);
- if (fields != null) opts['fields'] = fields;
- var query = query;
- if (query["$query"] != null && query["$orderby"] != null){
- opts['sort'] = query["$orderby"];
- query = query["$query"];
- }
- collection.find(query, opts,
- function (err, cursor) {
- return_(cont, {f1:(err === null || typeof err == 'undefined') ? "" : err.message, f2:cursor})
- });
- return;
-}
-
-/**
- * @register {Mongo.reply, continuation(int) -> void}
- * @cpsBypass
- */
-function count(cursor, cont) {
- cursor.count(function (err, count) {
- return_(cont, ((err !== null && typeof err != 'undefined') ||
- count === null || typeof count == 'undefined') ? 0 : count);
- });
- return;
-}
-
-/**
- * @register {Mongo.reply, continuation(tuple_2(string, NodeBson.document)) -> void}
- * @cpsBypass
- */
-function nextObject(cursor, cont) {
- cursor.nextObject(function (err, item) {
- if (err === null && item != null){
- return_(cont, {f1:"", f2:item})
- } else {
- var msg = err == null ? "No item" : err.message == null ? "No item" : err.message;
- cursor.close();
- return_(cont, {f1:msg == null ? "No item" : msg, f2:0})
- }
- });
- return;
-}
-
-/**
- * @register {Mongo.reply -> void}
- */
-function cclose(c) {
- c.close();
- return;
-}
-
-/**
- * @register {NodeMongo.collection, list(NodeBson.document), bool, \
- bool, continuation(tuple_2(string,list(NodeBson.document))) \
- -> void}
- * @cpsBypass
- */
-function insert(collection, docs, keepGoing, safe, cont) {
- var opts = {keepGoing:getbool(keepGoing),
- safe:getbool(safe)}; // TODO: w, wtimeout
- collection.insert(list2js(docs), opts,
- function (err, insertedDocs) {
- // The _id field can be a hideous ObjectID object, Opa just uses the string id
- // which is buried in the object, string representation: _id.__id, binary: _id.id
- insertedDocs.map(function (o) { if (o._id._bsontype === 'ObjectID') o._id = o._id.__id; });
- return_(cont, {f1:(err === null || typeof err == 'undefined') ? "" : err.message,
- f2:js2list(insertedDocs)});
- });
- return;
-}
-
-/**
- * @register {NodeMongo.collection, NodeBson.document, \
- NodeBson.document, bool, bool, bool, \
- continuation(tuple_2(string,int)) -> void}
- * @cpsBypass
- */
-function update(collection, selector, update, upsert, multi, safe, cont) {
- var opts = {upsert:un_uniformize_bool(upsert),
- multi:un_uniformize_bool(multi),
- safe:un_uniformize_bool(safe)};
- collection.update(selector, update, opts,
- function (err, numberOfUpdatedDocs) {
- // numberOfUpdatedDocs will be undefined if safe is false
- return_(cont, {f1:(err === null || typeof err == 'undefined') ? "" :
- err.message, f2:numberOfUpdatedDocs ? numberOfUpdatedDocs : 0});
- });
- return;
-}
-
-/**
- * @register {NodeMongo.collection, NodeBson.document, bool, continuation(tuple_2(string,int)) -> void}
- * @cpsBypass
- */
-function remove(collection, selector, safe, cont) {
- var opts = {safe:getbool(safe)};
- collection.remove(selector, opts,
- function (err, numberOfRemovedDocs) {
- // numberOfRemovedDocs will be undefined if safe is false
- return_(cont, {f1:(err === null || typeof err == 'undefined') ? "" : err.message,
- f2:numberOfRemovedDocs ? numberOfRemovedDocs : 0})
- });
- return;
-}
-
-/**
- * @register {NodeMongo.collection, NodeBson.document, bool, bool, bool, \
- bool, bool, continuation(tuple_2(string,string)) -> void}
- * @cpsBypass
- */
-function createIndex(collection, fieldOrSpec, unique, sparse, background, dropDups, safe, cont) {
- var opts = {unique:getbool(unique),
- sparse:getbool(sparse),
- background:getbool(background),
- dropDups:getbool(dropDups),
- safe:getbool(safe)};
- collection.createIndex(fieldOrSpec, opts,
- function (err, indexName) {
- return_(cont, {f1:(err === null || typeof err == 'undefined') ? "" : err.message,
- f2:indexName ? indexName : ""});
- });
- return;
-}
-
-// Not needed by db.opa but here for test code
-/**
- * @register {NodeMongo.collection, string, continuation(tuple_2(string,NodeBson.document)) -> void}
- * @cpsBypass
- */
-function dropIndex(collection, name, cont) {
- collection.dropIndex(name,
- function (err, result) {
- return_(cont, {f1:(err === null || typeof err == 'undefined') ? "" :
- err.message, f2:result});
- });
- return;
-}
-
-/**
- * @register {NodeMongo.db, string, string, continuation(tuple_2(string,bool)) -> void}
- * @cpsBypass
- */
-function authenticate(db, name, password, cont) {
- db.authenticate(name,password,
- function (err, res) {
- var auth = err === null || typeof err == 'undefined';
- return_(cont, {f1:auth ? "" : err.message, f2: auth});
- }
- );
- return;
-}
-
-/** @endModule */
View
1  lib/plugins/mongo/bslUtils.ml
View
3  lib/plugins/mongo/mongo.opa_plugin
@@ -1,3 +0,0 @@
-bslUtils.ml
-bslMongo.ml
-bslMongo.nodejs
View
0  lib/stdlib/apis/mongo/common/bson.opa → lib/stdlib/apis/mongo/bson.opa
File renamed without changes
View
34 lib/stdlib/apis/mongo/common.opa
@@ -10,7 +10,6 @@
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package stdlib.apis.mongo
-import stdlib.apis.mongo.common
/**
* MongoDB binding for OPA.
@@ -123,13 +122,13 @@ MongoCommon = {{
_OP_QUERY = 2004
/** Return new Bson Object ID */
- new_oid = WP.new_oid //(%% BslMongo.Bson.new_oid %%: void -> string)
+ new_oid = WP.new_oid
/** Get OID from string */
- oid_of_string = WP.oid_of_string //(%% BslMongo.Bson.oid_of_string %%: string -> string)
+ oid_of_string = WP.oid_of_string
/** Get string from OID */
- oid_to_string = WP.oid_to_string //(%% BslMongo.Bson.oid_to_string %%: string -> string)
+ oid_to_string = WP.oid_to_string
/** Generate a driver error message outcome **/
failErr(msg:string): outcome('a,Mongo.failure) = {failure={Error=msg}}
@@ -421,29 +420,26 @@ MongoCommon = {{
string_of_tags(tags:list(Mongo.mongo_tag)): string = List.list_to_string(string_of_tag,tags)
/** Access components of the reply value **/
- reply_messageLength = WP.reply_messageLength//(%% BslMongo.Mongo.reply_messageLength %% : Mongo.reply -> int)
- reply_requestId = WP.reply_requestId//(%% BslMongo.Mongo.reply_requestId %% : Mongo.reply -> int)
- reply_responseTo = WP.reply_responseTo//(%% BslMongo.Mongo.reply_responseTo %% : Mongo.reply -> int)
- reply_opCode = WP.reply_opCode//(%% BslMongo.Mongo.reply_opCode %% : Mongo.reply -> int)
- reply_responseFlags = WP.reply_responseFlags//(%% BslMongo.Mongo.reply_responseFlags %% : Mongo.reply -> int)
- reply_cursorID = WP.reply_cursorID//(%% BslMongo.Mongo.reply_cursorID %% : Mongo.reply -> Mongo.cursorID)
- reply_startingFrom = WP.reply_startingFrom//(%% BslMongo.Mongo.reply_startingFrom %% : Mongo.reply -> int)
- reply_numberReturned = WP.reply_numberReturned//(%% BslMongo.Mongo.reply_numberReturned %% : Mongo.reply -> int)
+ reply_messageLength = WP.reply_messageLength
+ reply_requestId = WP.reply_requestId
+ reply_responseTo = WP.reply_responseTo
+ reply_opCode = WP.reply_opCode
+ reply_responseFlags = WP.reply_responseFlags
+ reply_cursorID = WP.reply_cursorID
+ reply_startingFrom = WP.reply_startingFrom
+ reply_numberReturned = WP.reply_numberReturned
/** Return the n'th document attached to the reply **/
- reply_document = WP.reply_document_pos//(%% BslMongo.Mongo.reply_document %% : Mongo.reply, int -> option(Bson.document))
-
- /** Debug routine, export the internal representation of the reply **/
- //export_reply = (%% BslMongo.Mongo.export_reply %%: Mongo.reply -> string)
+ reply_document = WP.reply_document_pos
/** Null cursor value **/
- null_cursorID(_) = Int64.zero//(%% BslMongo.Mongo.null_cursorID %% : void -> Mongo.cursorID)
+ null_cursorID(_) = Int64.zero
/** Return a string representation of a cursor (it's an int64) **/
- string_of_cursorID(cid) = Int64.to_string_radix(cid,16)//(%% BslMongo.Mongo.string_of_cursorID %% : Mongo.cursorID -> string)
+ string_of_cursorID(cid) = Int64.to_string_radix(cid,16)
/** Predicate for end of query, when the cursorID is returned as zero **/
- is_null_cursorID(cid) = Int64.op_eq(cid,Int64.zero)//(%% BslMongo.Mongo.is_null_cursorID %% : Mongo.cursorID -> bool)
+ is_null_cursorID(cid) = Int64.op_eq(cid,Int64.zero)
/**
* Extract a document from a reply.
View
0  lib/stdlib/apis/mongo/common/log.opa → lib/stdlib/apis/mongo/log.opa
File renamed without changes
View
2  lib/stdlib/apis/mongo/mongo.opa
@@ -9,7 +9,7 @@
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-import-plugin mongo
+
package stdlib.apis.mongo
/**
View
378 lib/stdlib/apis/mongo/node/mongo.opa
@@ -1,378 +0,0 @@
-import-plugin mongo
-import stdlib.apis.mongo.common
-/* Minimal implementation required for db.opa */
-
-type NodeMongo.server = external
-type NodeMongo.db = external
-type NodeMongo.collection = external
-type Mongo.reply = external
-
-type NodeBson.document = external
-type NodeBson.value = external
-
-/**
- * Main connection type.
- * Stores the socket connection plus other parameters such as
- * the seeds, timing parameters for reconnection and a limiter for recursion depth.
- **/
-@abstract
-type Mongo.db = {
- log : bool;
- name : string;
- allow_slaveok : bool;
-
- // For node.js
- server : NodeMongo.server;
- db : option((string, NodeMongo.db));
- collection : option((string, NodeMongo.collection));
-
- auth : Mongo.auths
-}
-
-
-@abstract type Mongo.cursorID = Mongo.reply
-
-@private
-NodeMongo = {{
-
- server = %% BslMongo.NodeMongo.server %%
- : string, int, bool, int -> NodeMongo.server
-
- replset = %% BslMongo.NodeMongo.replset %%
- : list(NodeMongo.server) -> NodeMongo.server
-
- db = %% BslMongo.NodeMongo.db %%
- : NodeMongo.server, string, bool -> NodeMongo.db
-
- open = %% BslMongo.NodeMongo.open %%
- : NodeMongo.db -> (string, NodeMongo.db)
-
- authenticate = %% BslMongo.NodeMongo.authenticate %% : NodeMongo.db, string, string -> (string,bool)
-
- get_database = %%BslMongo.NodeMongo.get_database%%
- : NodeMongo.server, string, bool -> (string, NodeMongo.db)
-
- close = %% BslMongo.NodeMongo.close %%
- : NodeMongo.db -> string
-
- collection = %% BslMongo.NodeMongo.collection %%
- : NodeMongo.db, string -> (string, NodeMongo.collection)
-
- query = %% BslMongo.NodeMongo.query %%
- : NodeMongo.collection, int, int, NodeBson.document, option(NodeBson.document)
- -> (string,Mongo.reply)
-
- count = %% BslMongo.NodeMongo.count %%
- : Mongo.reply -> int
-
- nextObject = %% BslMongo.NodeMongo.nextObject %%
- : Mongo.reply -> (string, NodeBson.document)
-
- insert = %% BslMongo.NodeMongo.insert %%
- : NodeMongo.collection, list(NodeBson.document), bool, bool
- -> (string,list(NodeBson.document))
-
- update = %% BslMongo.NodeMongo.update %%
- : NodeMongo.collection, NodeBson.document, NodeBson.document, bool, bool, bool
- -> (string,int)
-
- remove = %% BslMongo.NodeMongo.remove %%
- : NodeMongo.collection, NodeBson.document, bool -> (string,int)
-
- createIndex = %% BslMongo.NodeMongo.createIndex %%
- : NodeMongo.collection, NodeBson.document, bool, bool, bool, bool, bool
- -> (string,string)
-
-}}
-
-@private
-NodeBson = {{
- @private
- Document = {{
- empty = %%BslMongo.NodeBson.empty_document%%
- add = %%BslMongo.NodeBson.add_element%%
-
- array = %%BslMongo.NodeBson.empty_array%%
- }}
-
- @private
- Value = {{
- float(f) = %%BslMongo.NodeBson.float_value%%(f)
- string(s) = %%BslMongo.NodeBson.string_value%%(s)
- of_bool(b) = %%BslMongo.NodeBson.bool_value%%(b)
- of_int32(i) = %%BslMongo.NodeBson.int32_value%%(i)
- of_timestamp(t) = %%BslMongo.NodeBson.timestamp_value%%(t.f1, t.f2)
- of_int(i) = %%BslMongo.NodeBson.int_value%%(i)
- of_int64(i) = %%BslMongo.NodeBson.int64_value%%(i)
-
- of_doc(d) = %%BslMongo.NodeBson.document_value%%(d)
- of_array(a) = %%BslMongo.NodeBson.array_value%%(a)
- of_binary(b) = %%BslMongo.NodeBson.binary_value%%(b)
- of_object_id(o) = %%BslMongo.NodeBson.object_id_value%%(o)
- of_date(d) = %%BslMongo.NodeBson.date_value%%(Date.in_milliseconds(d))
- null() = %%BslMongo.NodeBson.null_value%%()
- regexp(r) = %%BslMongo.NodeBson.regexp_value%%(r.f1, r.f2)
- of_code(c) = %%BslMongo.NodeBson.code_value%%(c)
- of_symbol(s) = %%BslMongo.NodeBson.symbol_value%%(s)
- of_code_scope(s) = %%BslMongo.NodeBson.code_scope_value%%(s.f1, of_document(s.f2))
- min_key() = %%BslMongo.NodeBson.min_value%%()
- max_key() = %%BslMongo.NodeBson.max_value%%()
- }}
-
- @private
- fill_document(init:NodeBson.document, doc : Bson.document) =
- do List.iter(~{name value} -> Document.add(init, name, of_value(value)), doc)
- init
-
- of_document(doc : Bson.document):NodeBson.document =
- fill_document(Document.empty(), doc)
-
- of_array(doc : Bson.document):NodeBson.document =
- fill_document(Document.array(), doc)
-
- of_value(value:Bson.value):NodeBson.value =
- match value with
- | { Double = d } -> Value.float(d)
- | { String = s } -> Value.string(s)
- | { Boolean = b } -> Value.of_bool(b)
- | { RealInt32 = i } -> Value.of_int32(i:int32)
- | { Timestamp = t } -> Value.of_timestamp(t)
- | { Int32 = i }
- | { Int64 = i } -> Value.of_int(i)
- | { RealInt64 = i } -> Value.of_int64(i)
- | { Array = a } -> Value.of_array(of_array(a))
- | { Document = d } -> Value.of_doc(of_document(d))
- | { Binary = b } -> Value.of_binary(b)
- | { ObjectID = o } -> Value.of_object_id(o)
- | { Date = d } -> Value.of_date(d)
- | { Null } -> Value.null()
- | { Regexp = r } -> Value.regexp(r)
- | { Code = c } -> Value.of_code(c)
- | { Symbol = s } -> Value.of_symbol(s)
- | { CodeScope = c } -> Value.of_code_scope(c)
- | { Min } -> Value.min_key()
- | { Max } -> Value.max_key()
-
- to_document(doc : NodeBson.document) : Bson.document =
- %%BslMongo.NodeBson.to_document%%(doc)
-}}
-
-MongoCommon = {{
-
-
- /* OP_INSERT */
- ContinueOnErrorBit = 0x00000001
-
- /* OP_UPDATE */
- UpsertBit = 0x00000001
- MultiUpdateBit = 0x00000002
-
- /* OP_QUERY */
- TailableCursorBit = 0x00000002
- SlaveOkBit = 0x00000004
- OplogReplayBit = 0x00000008
- NoCursorTimeoutBit = 0x00000010
- AwaitDataBit = 0x00000020
- ExhaustBit = 0x00000040
- PartialBit = 0x00000080
-
- /* OP_DELETE */
- SingleRemoveBit = 0x00000001
-
- /* OP_REPLY */
- CursorNotFoundBit = 0x00000001
- QueryFailureBit = 0x00000002
- ShardConfigStaleBit = 0x00000004
- AwaitCapableBit = 0x00000008
-
- /* Flags used by the index routines. */
- UniqueBit = 0x00000001
- DropDupsBit = 0x00000002
- BackgroundBit = 0x00000004
- SparseBit = 0x00000008
-
- // Warning: this does a db access
- reply_numberReturned(reply): int = NodeMongo.count(reply)
-
- // Warning: this only ever returns the next document, NOT the nth document in the reply
- reply_document(reply, _): option(Bson.document) =
- match NodeMongo.nextObject(reply) with
- | ("", doc) -> {some=NodeBson.to_document(doc)}
- | (_err, _) -> {none}
-
-}}
-
-MongoDriver = {{
-
- // Note that we don't open any connection here, we just instantiate a Server object
- // Actually opening the connection is done by the namespace checks on each command
- open(_bufsize:int, pool_max:int, reconnectable:bool, allow_slaveok:bool, addr:string, port:int, log:bool, auth:Mongo.auths)
- : outcome(Mongo.db,Mongo.failure) =
- do if log then MongoLog.info("MongoDriver.open","{addr}:{port}",void)
- {success =
- { server=NodeMongo.server(addr, port, reconnectable, pool_max);
- db=none;
- collection=none;
- ~log;
- ~allow_slaveok
- ~auth
- name="";
- }
- }
-
- @private
- authenticate(db:NodeMongo.db, auth:Mongo.auth):bool = NodeMongo.authenticate(db,auth.user,auth.password).f2
-
- close(db:Mongo.db): outcome(Mongo.db,Mongo.failure) =
- match db.db with
- | {some=(_,odb)} ->
- match NodeMongo.close(odb) with
- | "" -> {success={db with db={some=("",odb)}}}
- | err -> {failure={Error=err}}
- end
- | {none} -> {success=db}
-
- reopen(db:Mongo.db, dbname:string): outcome(Mongo.db,Mongo.failure) =
- match close(db) with
- | {success=db} ->
- match NodeMongo.get_database(db.server, dbname, db.allow_slaveok) with
- | ("", ndb) ->
- authentified = List.for_all(authenticate(ndb, _), db.auth)
- if authentified then {success={db with db={some=(dbname, ndb)}}}
- else {failure={Error="Authentification fails"}}
- | (err, _) -> {failure={Error=err}}
- end
- | {~failure} -> {~failure}
-
- check_dbname(db:Mongo.db, dbname:string): outcome(Mongo.db,Mongo.failure) =
- match db.db with
- | {some=(dbn, _)} ->
- if dbn == dbname then
- {success = db}
- else
- do Log.notice("Reopen", "{dbn} vs {dbname}")
- reopen(db, dbname)
- | {none} -> reopen(db, dbname)
-
- redocollection(db:Mongo.db, collection:string): outcome(Mongo.db,Mongo.failure) =
- odb = match db.db with | {some=(_,odb)} -> odb | {none} -> @fail // db must be open
- match NodeMongo.collection(odb, collection) with
- | ("", coll) -> {success={db with collection={some=(collection, coll)}}}
- | (err, _) -> {failure={Error=err}}
-
- check_collection(db:Mongo.db, collection:string): outcome(Mongo.db,Mongo.failure) =
- match db.collection with
- | {some=(cname, _coll)} -> if cname == collection then {success=db} else redocollection(db, collection)
- | {none} -> redocollection(db, collection)
-
- check_namespace(db:Mongo.db, dbname:string, collection:string): outcome(Mongo.db,Mongo.failure) =
- match check_dbname(db, dbname) with
- | {success=db} -> check_collection(db, collection)
- | {~failure} -> {~failure}
-
- check_ns(db:Mongo.db, ns:string): outcome(Mongo.db,Mongo.failure) =
- match String.explode(".",ns) with
- | [] -> {failure={Error="bad namespace \"{ns}\""}}
- | [dbname|coll] -> check_namespace(db, dbname, String.concat(".",coll))
-
- // TODO: db.opa uses the unsafe routines so we should log errors internally here
-
- // Note: we don't actually get access to the raw reply with the node.js driver
- // Here, the reply is actually the cursor
- query(m:Mongo.db, _flags:int, ns:string, numberToSkip:int, numberToReturn:int,
- query:Bson.document, returnFieldSelector_opt:option(Bson.document)): option(Mongo.reply) =
- query = NodeBson.of_document(query)
- returnFieldSelector_opt = Option.map(NodeBson.of_document, returnFieldSelector_opt)
- match check_ns(m, ns) with
- | {success=db} ->
- (match db.collection with
- | {some=(_,coll)} ->
- (match NodeMongo.query(coll, numberToSkip, numberToReturn, query, returnFieldSelector_opt) with
- | ("", cursor) -> {some=cursor}
- | (_err, _) -> {none})
- | {none} -> {none})
- | {failure=_} -> {none}
-
- insert_batch(m:Mongo.db, flags:int, ns:string, documents:list(Bson.document)): bool =
- documents = List.map(NodeBson.of_document, documents)
- match check_ns(m, ns) with
- | {success=db} ->
- (match db.collection with
- | {some=(_,coll)} ->
- keepGoing = Bitwise.land(flags,MongoCommon.ContinueOnErrorBit) != 0
- (match NodeMongo.insert(coll, documents, keepGoing, false/*safe*/) with
- | ("", _result) -> true // numberInserted???
- | (_err, _) -> false)
- | {none} -> false)
- | {failure=_} -> false
-
- updatee(m:Mongo.db, flags:int, ns:string, _dbname:string, selector:Bson.document, update:Bson.document): bool =
- selector = NodeBson.of_document(selector)
- update = NodeBson.of_document(update)
- match check_ns(m, ns) with
- | {success=db} ->
- (match db.collection with
- | {some=(_,coll)} ->
- upsert = Bitwise.land(flags,MongoCommon.UpsertBit) != 0
- multi = Bitwise.land(flags,MongoCommon.MultiUpdateBit) != 0
- (match NodeMongo.update(coll, selector, update, upsert, multi, false/*safe*/) with
- | ("", _numberUpdated) -> true
- | (_err, _) -> false)
- | {none} -> false)
- | {failure=_} -> false
-
- delete(m:Mongo.db, _flags:int, ns:string, selector:Bson.document): bool =
- selector = NodeBson.of_document(selector)
- match check_ns(m, ns) with
- | {success=db} ->
- (match db.collection with
- | {some=(_,coll)} ->
- (match NodeMongo.remove(coll, selector, false/*safe*/) with
- | ("", _numberRemoved) -> true
- | (_err, _) -> false)
- | {none} -> false)
- | {failure=_} -> false
-
- create_index(m:Mongo.db, ns:string, key:Bson.document, options:int): bool =
- key = NodeBson.of_document(key)
- match check_ns(m, ns) with
- | {success=db} ->
- (match db.collection with
- | {some=(_,coll)} ->
- unique = Bitwise.land(options,MongoCommon.UniqueBit) != 0
- sparse = Bitwise.land(options,MongoCommon.SparseBit) != 0
- background = Bitwise.land(options,MongoCommon.BackgroundBit) != 0
- dropDups = Bitwise.land(options,MongoCommon.DropDupsBit) != 0
- (match NodeMongo.createIndex(coll, key, unique, sparse, background, dropDups, false/*safe*/) with
- | ("", _indexName) -> true
- | (_err, _) -> false)
- | {none} -> false)
- | {failure=_} -> false
-
- check(m:Mongo.db) = {success = m} //TODO
-
- cclose(r:Mongo.reply) =
- %%BslMongo.NodeMongo.cclose%%(r)
-
-}}
-
-MongoReplicaSet = {{
-
- init(name:string, _bufsize:int, pool_max:int, allow_slaveok:bool, log:bool, auth:Mongo.auths, seeds:list(Mongo.mongo_host)): Mongo.db =
- do if log then MongoLog.info("MongoReplicaSet.init","seeds={seeds}",void)
- servers = List.map((((host, port)) -> NodeMongo.server(host, port, true, pool_max)), seeds)
- replset = NodeMongo.replset(servers)
- { server=replset;
- db=none;
- collection=none;
- ~log;
- name=name;
- ~allow_slaveok
- ~auth
- }
-
- connect(m:Mongo.db): outcome((bool,Mongo.db),Mongo.failure) =
- // TODO: find out how node.js knows it's connected to a secondary, if not do an isMaster call
- {success=(false,m)}
-
-}}
View
0  lib/stdlib/apis/mongo/common/type.opa → lib/stdlib/apis/mongo/type.opa
File renamed without changes
View
2  lib/stdlib/apis/mongo/wire_protocol.opa
@@ -9,7 +9,7 @@
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-import-plugin mongo
+
package stdlib.apis.mongo
/**
View
19 lib/stdlib/database/mongo/db.opa
@@ -19,12 +19,7 @@ import-plugin unix
package stdlib.database.mongo
import stdlib.core.{date,map,parser}
-//# <Ifstatic:OPA_BACKEND_QMLJS>
-//import stdlib.apis.mongo.node
-//# <Else>
import stdlib.apis.mongo
-//# <End>
-import stdlib.apis.mongo.common
import stdlib.system
import stdlib.database.common
@@ -87,12 +82,6 @@ DbMongo = {{
@package updateerr(db:DbMongo.t2, flags:int, ns:string, selector:Bson.document, update:Bson.document, id , upsert): void =
reply = MongoDriver.updatee(db.db, flags, ns, db.name, selector, update)
-// # <Ifstatic:OPA_BACKEND_QMLJS>
-// _=id
-// _=upsert
-// if reply then void
-// else error("Update error")
-// # <Else>
match reply with
| {none} ->
do Log.error("DbGen/Query", "(failure) Read {id} didn't return anything")
@@ -137,9 +126,6 @@ DbMongo = {{
do Log.error("DbGen/Mongo", "(failure) read from {id} didn't return any document")
none
| {some=document} ->
-// # <Ifstatic:OPA_BACKEND_QMLJS>
-// do MongoDriver.cclose(reply)
-// # <End>
#<Ifstatic:DBGEN_DEBUG>
do Log.notice("DbGen/Mongo", "(success) read bson document from mongo db returned")
#<End>
@@ -782,11 +768,6 @@ DbMongoSet = {{
error("DbSet build error")
| {some=reply} ->
rec next(consummed, reply) =
-// # <Ifstatic:OPA_BACKEND_QMLJS>
-// _ = consummed
-// do MongoDriver.cclose(reply)
-// {none}
-// # <Else>
cursor = MongoCommon.reply_cursorID(reply)
if MongoCommon.is_null_cursorID(cursor) then
none
Please sign in to comment.
Something went wrong with that request. Please try again.