Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file caqti_connect.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128(* Copyright (C) 2014--2020 Petter A. Urkedal <paurkedal@gmail.com>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version, with the OCaml static compilation exception.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*)openPrintfletdynload_library=ref@@funlib->Error(sprintf"Neither %s nor the dynamic linker is linked into the \
application."lib)letdefine_loaderf=dynload_library:=fletdrivers=Hashtbl.create11letdefine_unix_driverschemep=Hashtbl.adddriversschemepletscheme_driver_name=function|"postgres"|"postgresql"->"caqti-driver-postgresql"|s->"caqti-driver-"^sletload_driver_functor~urischeme=(tryOk(Hashtbl.finddriversscheme)with|Not_found->(match!dynload_library(scheme_driver_namescheme)with|Ok()->(tryOk(Hashtbl.finddriversscheme)with|Not_found->letmsg=sprintf"The driver for %s did not register itself \
after apparently loading."schemeinError(Caqti_error.load_failed~uri(Caqti_error.Msgmsg)))|Errormsg->Error(Caqti_error.load_failed~uri(Caqti_error.Msgmsg))))moduleMake_unix(System:Caqti_driver_sig.System_unix)=structopenSystemmoduletypeDRIVER=Caqti_driver_sig.Swithtype'afuture:='aSystem.futureandtype('a,'err)stream:=('a,'err)System.Stream.tletdrivers:(string,(moduleDRIVER))Hashtbl.t=Hashtbl.create11letload_driveruri=(matchUri.schemeuriwith|None->letmsg="Missing URI scheme."inError(Caqti_error.load_rejected~uri(Caqti_error.Msgmsg))|Somescheme->(tryOk(Hashtbl.finddriversscheme)with|Not_found->(matchload_driver_functor~urischemewith|Okmake_driver->letmoduleMake_driver=(valmake_driver:Caqti_driver_sig.Of_system_unix)inletmoduleDriver=Make_driver(System)inletdriver=(moduleDriver:DRIVER)inHashtbl.adddriversschemedriver;Okdriver|Error_asr->r)))moduletypeCONNECTION_BASE=Caqti_connection_sig.Basewithtype'afuture:='aSystem.futureandtype('a,'err)stream:=('a,'err)System.Stream.tmoduletypeCONNECTION=Caqti_connection_sig.Swithtype'afuture:='aSystem.futureandtype('a,'err)stream:=('a,'err)System.Stream.ttypeconnection=(moduleCONNECTION)letconnecturi:((moduleCONNECTION),_)resultfuture=(matchload_driveruriwith|Okdriver->letmoduleDriver=(valdriver)inDriver.connecturi|Errorerr->return(Errorerr))modulePool=Caqti_pool.Make(System)moduleStream=System.Streamletconnect_pool?max_size?max_idle_sizeuri=letcheck_argcond=ifnotcondtheninvalid_arg"Caqti_connect.Make_unix.connect_pool"in(matchmax_size,max_idle_sizewith|None,None->()|Somemax_size,None->check_arg(max_size>=0)|None,Some_->check_argfalse|Somemax_size,Somemax_idle_size->check_arg(max_size>=0);check_arg(0<=max_idle_size&&max_idle_size<=max_size));(matchload_driveruriwith|Okdriver->letmoduleDriver=(valdriver)inletconnect()=Driver.connecturiinletdisconnect(moduleDb:CONNECTION)=Db.disconnect()inletvalidate(moduleDb:CONNECTION)=Db.validate()inletcheck(moduleDb:CONNECTION)=Db.checkinletdi=Driver.driver_infoinletmax_size,max_idle_size=(matchCaqti_driver_info.can_concurdi,Caqti_driver_info.can_pooldi,max_idle_sizewith|true,true,_->max_size,max_idle_size|true,false,_->max_size,Some0|false,true,Some0->Some1,Some0|false,true,_->Some1,Some1|false,false,_->Some1,Some0)inletpool=Pool.create?max_size?max_idle_size~validate~checkconnectdisconnectinOkpool|Errorerr->Errorerr)end