text stringlengths 12 786k |
|---|
let get_port m = m . port ; ; |
let get_channel_pool m = m . channel_pool ; ; |
let change_collection m c = { m with collection_name = c ; } |
let wrap_bson f arg = try ( f arg ) with | Bson . Invalid_objectId -> raise ( Mongo_failed " Bson . Invalid_objectId " ) | Bson . Wrong_bson_type -> raise ( Mongo_failed " Wrong_bson_type when encoding bson doc " ) | Bson . Malformed_bson -> raise ( Mongo_failed " Malformed_bson w... |
let wrap_unix_lwt f arg = try_lwt ( f arg ) with | Unix . Unix_error ( e , _ , _ ) -> raise ( Mongo_failed ( Unix . error_message e ) ) ; ; |
let connect_to ( ip , port ) = let s_addr = Lwt_unix . ADDR_INET ( Unix . inet_addr_of_string ip , port ) in Lwt_io . open_connection s_addr |
let create ( ? max_connection = 10 ) ip port db_name collection_name = let channel_pool = Lwt_pool . create max_connection ( fun _ -> wrap_unix_lwt connect_to ( ip , port ) ) in Lwt . return { db_name = db_name ; collection_name = collection_name ; ip = ip ; port = port ; channel_... |
let create_local_default db_name collection_name = create " 127 . 0 . 0 . 1 " 27017 db_name collection_name ; ; |
let destroy m = let close ( ) = Lwt_pool . use m . channel_pool ( fun ( i , o ) -> lwt _ = wrap_unix_lwt Lwt_io . close i in wrap_unix_lwt Lwt_io . close o ) in let build_thread acc i = if i = m . max_connection then acc else ( close ( ) :: acc ) in let ths = build_thread [ ] ... |
let send_only ( m , str ) = MongoSend_lwt . send_no_reply m . channel_pool str ; ; |
let send ( m , str ) = MongoSend_lwt . send_with_reply m . channel_pool str ; ; |
let insert_in ( m , flags , doc_list ) = MongoRequest . create_insert ( m . db_name , m . collection_name ) ( get_request_id ( ) , flags ) doc_list ; ; |
let insert m doc_list = wrap_unix_lwt send_only ( m , wrap_bson insert_in ( m , 0l , doc_list ) ) ; ; |
let update_in ( m , flags , s , u ) = MongoRequest . create_update ( m . db_name , m . collection_name ) ( get_request_id ( ) , flags ) ( s , u ) ; ; |
let update_one ( ? upsert = false ) m ( s , u ) = wrap_unix_lwt send_only ( m , wrap_bson update_in ( m , ( if upsert then 1l else 0l ) , s , u ) ) ; ; |
let update_all ( ? upsert = false ) m ( s , u ) = wrap_unix_lwt send_only ( m , wrap_bson update_in ( m , ( if upsert then 3l else 2l ) , s , u ) ) ; ; |
let delete_in ( m , flags , s ) = MongoRequest . create_delete ( m . db_name , m . collection_name ) ( get_request_id ( ) , flags ) s ; ; |
let delete_one m s = wrap_unix_lwt send_only ( m , wrap_bson delete_in ( m , 1l , s ) ) ; ; |
let delete_all m s = wrap_unix_lwt send_only ( m , wrap_bson delete_in ( m , 0l , s ) ) ; ; |
let find_in ( m , flags , skip , return , q , s ) = MongoRequest . create_query ( m . db_name , m . collection_name ) ( get_request_id ( ) , flags , skip , return ) ( q , s ) ; ; |
let find ( ? skip = 0 ) m = wrap_unix_lwt send ( m , wrap_bson find_in ( m , 0l , ( Int32 . of_int skip ) , 0l , Bson . empty , Bson . empty ) ) ; ; |
let find_one ( ? skip = 0 ) m = wrap_unix_lwt send ( m , wrap_bson find_in ( m , 0l , ( Int32 . of_int skip ) , 1l , Bson . empty , Bson . empty ) ) ; ; |
let find_of_num ( ? skip = 0 ) m num = wrap_unix_lwt send ( m , wrap_bson find_in ( m , 0l , ( Int32 . of_int skip ) , ( Int32 . of_int num ) , Bson . empty , Bson . empty ) ) ; ; |
let find_q ( ? skip = 0 ) m q = wrap_unix_lwt send ( m , wrap_bson find_in ( m , 0l , ( Int32 . of_int skip ) , 0l , q , Bson . empty ) ) ; ; |
let find_q_one ( ? skip = 0 ) m q = wrap_unix_lwt send ( m , wrap_bson find_in ( m , 0l , ( Int32 . of_int skip ) , 1l , q , Bson . empty ) ) ; ; |
let find_q_of_num ( ? skip = 0 ) m q num = wrap_unix_lwt send ( m , wrap_bson find_in ( m , 0l , ( Int32 . of_int skip ) , ( Int32 . of_int num ) , q , Bson . empty ) ) ; ; |
let find_q_s ( ? skip = 0 ) m q s = wrap_unix_lwt send ( m , wrap_bson find_in ( m , 0l , ( Int32 . of_int skip ) , 0l , q , s ) ) ; ; |
let find_q_s_one ( ? skip = 0 ) m q s = wrap_unix_lwt send ( m , wrap_bson find_in ( m , 0l , ( Int32 . of_int skip ) , 1l , q , s ) ) ; ; |
let find_q_s_of_num ( ? skip = 0 ) m q s num = wrap_unix_lwt send ( m , wrap_bson find_in ( m , 0l , ( Int32 . of_int skip ) , ( Int32 . of_int num ) , q , s ) ) ; ; |
let count ? skip ? limit ( ? query = Bson . empty ) m = let c_bson = Bson . add_element " count " ( Bson . create_string m . collection_name ) Bson . empty in let c_bson = Bson . add_element " query " ( Bson . create_doc_element query ) c_bson in let c_bson = match limit with ... |
let get_more_in ( m , c , num ) = MongoRequest . create_get_more ( m . db_name , m . collection_name ) ( get_request_id ( ) , Int32 . of_int num ) c ; ; |
let get_more_of_num m c num = wrap_unix_lwt send ( m , wrap_bson get_more_in ( m , c , num ) ) ; ; |
let get_more m c = get_more_of_num m c 0 ; ; |
let kill_cursors_in c_list = MongoRequest . create_kill_cursors ( get_request_id ( ) ) c_list ; ; |
let kill_cursors m c_list = wrap_unix_lwt send_only ( m , wrap_bson kill_cursors_in c_list ) ; ; |
let drop_database m = let m = change_collection m " $ cmd " in find_q_one m ( Bson . add_element " dropDatabase " ( Bson . create_int32 1l ) Bson . empty ) |
let drop_collection m = let m_ = change_collection m " $ cmd " in find_q_one m_ ( Bson . add_element " drop " ( Bson . create_string m . collection_name ) Bson . empty ) |
let get_indexes m = let m_ = change_collection m " system . indexes " in find_q m_ ( Bson . add_element " ns " ( Bson . create_string ( m . db_name ^ " . " ^ m . collection_name ) ) Bson . empty ) |
type index_option = | Background of bool | Unique of bool | Name of string | DropDups of bool | Sparse of bool | ExpireAfterSeconds of int | V of int | Weight of Bson . t | Default_language of string | Language_override of string |
let ensure_index m key_bson options = let default_name ( ) = let doc = Bson . get_element " key " key_bson in List . fold_left ( fun s ( k , e ) -> let i = Bson . get_int32 e in if s = " " then Printf . sprintf " % s_ % ld " k i else Printf . sprintf " % s_ % s_ % ld " s... |
let ensure_simple_index ( ? options [ ] ) = m field = let key_bson = Bson . add_element " key " ( Bson . create_doc_element ( Bson . add_element field ( Bson . create_int32 1l ) Bson . empty ) ) Bson . empty in ensure_index m key_bson options |
let ensure_multi_simple_index ( ? options [ ] ) = m fields = let key_bson = List . fold_left ( fun acc f -> Bson . add_element f ( Bson . create_int32 1l ) acc ) Bson . empty fields in let key_bson = Bson . add_element " key " ( Bson . create_doc_element key_bson ) Bson . em... |
let drop_index m index_name = let index_bson = Bson . add_element " index " ( Bson . create_string index_name ) Bson . empty in let delete_bson = Bson . add_element " deleteIndexes " ( Bson . create_string m . collection_name ) index_bson in let m = change_collection m " $ cmd " in ... |
let drop_all_index m = drop_index m " " * |
let test msg f arg r = if f arg <> r then begin prerr_endline msg ; failwith " Malaise " end ; ; |
type t = A | B | C | D | E | F ; ; |
let f x = match x with ; ; |
let g x = match x with 1 -> 1 ; ; ; ; |
let g x = match x with 1 -> 1 ; ; |
let g x = match x with 1 -> 1 ; ; ; ; |
let h x = match x with ( 1 , 1 ) -> 1 ; ; ; ; |
let hh x = match x with ; ; |
let hhh x = match x with ; ; |
let h x = match x with ( 1 , 1 ) -> 1 ; ; |
let h x = match x with 1 -> 1 ; ; |
let f x = match x with ; ; ; ; |
type tt = { a : bool list ; b : bool } |
let f = function | { a ( [ ] [ =| true ] ) } -> 1 | { a = false :: _ } { | b ( = true | false ) } -> 2 ; ; ; ; |
let f = function | ( ( [ ] [ | true ] ) , _ ) -> 1 | ( false :: _ , _ ) ( | _ , ( true | false ) ) -> 2 ; ; ; ; |
let split_cases = function | ` Nil | ` Cons _ as x -> ` A x | ` Snoc _ as x -> ` B x ; ; ; ; |
type t1 = A of int | B of int |
let f1 = function | ( A x | B x ) -> x ; ; ; ; |
type coucou = A of int | B of int * int | C ; ; |
let g = function | ( A x | B ( _ , x ) ) -> x | C -> 0 ; ; ; ; |
let h = function | ( [ x ] [ | 1 ; x ] [ | 1 ; 2 ; x ] ) -> x | _ -> 0 ; ; ; ; |
let f = function ; ; ; ; |
let f = function ( ( [ ] [ | _ ] ) as x ) ( | _ ( [ ] :: as x ) ) ( | _ :: _ :: x ) -> x ; ; ; ; |
type zob = A | B | C | D of zob * int | E of zob * zob |
let rec f = function | ( A | B | C ) -> A | D ( x , i ) -> D ( f x , i ) | E ( x , _ ) -> D ( f x , 0 ) ; ; ; ; |
type length = Char of int | Pixel of int | Percent of int | No of string | Default |
let length = function | Char n -> n | Pixel n -> n | _ -> 0 ; ; ; ; |
let length2 = function | Char n -> n | Percent n -> n | _ -> 0 ; ; ; ; |
let length3 = function | Char _ | No _ -> true | _ -> false ; ; ; ; |
type hevea = A | B | C |
let h x = match x with ; ; ; ; |
type lambda = Lvar of int | Lconst of int | Lapply of lambda * lambda list | Lfunction of bool * int list * lambda | Llet of bool * int * lambda * lambda | Lletrec of ( int * lambda ) list * lambda | Lprim of string * lambda list | Lswitch of lambda * lambda_switch | Lstaticfail | Lcatch of lamb... |
let rec approx_present v l = true |
let rec lower_bind v arg lam = match lam with when not ( approx_present v ls ) -> 2 when not ( approx_present v ls ) -> 3 ; ; ; ; |
type field_kind = Fvar of field_kind option ref | Fpresent | Fabsent |
let unify_kind ( k1 , k2 ) = match k1 , k2 with ( Fvar r , ( Fvar _ | Fpresent ) ) -> 1 | ( Fpresent , Fvar r ) -> 2 | ( Fpresent , Fpresent ) -> 3 | _ -> 4 |
let r = ref ( Some Fpresent ) ; ; ; ; |
type youyou = A | B | C | D of youyou |
let foo ( k1 , k2 ) = match k1 , k2 with ; ; ; ; |
type yaya = A | B ; ; |
let yaya = function ; ; ; ; |
let yoyo = function ; ; ; ; |
let youyou = function | ( 100 | 103 | 104 ) -> 1 | ( 100 | 103 | 101 ) -> 2 | ( 1000 | 1001 | 1002 | 20000 ) -> 3 | _ -> - 1 ; ; ; ; |
type autre = | C | D | E of autre | F of autre * autre | H of autre | I | J | K of string |
let rec autre = function ; ; ; ; |
type youpi = YA | YB | YC |
let xyz = function ; ; ; ; |
let eq ( x , y ) = x = y ; ; ; ; |
let is_none = function | None -> true | _ -> false |
let guard x = match x with ; ; ; ; |
let orstring = function | ( " A " " | B " " | C " ) -> 2 | " D " -> 3 | _ -> 4 ; ; ; ; |
type var_t = [ ` Variant of [ ` Some of string | ` None | ` Foo ] ] |
let crash ( pat : var_t ) = match pat with | ` Variant ( ` Some tag ) -> tag | ` Variant ( ` None ) -> " none " | _ -> " foo " ; ; ; ; |
let x , y = c in ; ; ; ; |
type f = | ABSENT | FILE | SYMLINK | DIRECTORY |
type r = | Unchanged | Deleted | Modified | PropsChanged | Created |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.