Skip to content

Commit

Permalink
fix naming convention for Io
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsoni committed May 4, 2020
1 parent 32b0306 commit 11c3adf
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 72 deletions.
8 changes: 4 additions & 4 deletions pgx/src/pgx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,12 @@ let deserialize_string str =

module Value = Pgx_value

module type IO = Io_intf.S
module type Io = Io_intf.S
module type S = Pgx_intf.S

module Make (Thread : IO) = struct
module IO = Thread
open IO
module Make (Thread : Io) = struct
module Io = Thread
open Io

type conn =
{ ichan : (in_channel[@sexp.opaque] (* In_channel wrapping socket. *))
Expand Down
4 changes: 2 additions & 2 deletions pgx/src/pgx.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*)
module type IO = Io_intf.S
module type Io = Io_intf.S

(* FIXME: I can't figure out how to not duplicate these types from types.ml *)
type oid = int32 [@@deriving sexp]
Expand Down Expand Up @@ -49,4 +49,4 @@ module Value = Pgx_value

module type S = Pgx_intf.S

module Make (Thread : IO) : S with type 'a IO.t = 'a Thread.t
module Make (Thread : Io) : S with type 'a Io.t = 'a Thread.t
76 changes: 38 additions & 38 deletions pgx/src/pgx_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Types
module type S = sig
type t

module IO : sig
module Io : sig
type 'a t

val return : 'a -> 'a t
Expand Down Expand Up @@ -31,12 +31,12 @@ module type S = sig
-> ?verbose:int
-> ?max_message_length:int
-> unit
-> t IO.t
-> t Io.t

(** Close the database handle. You must call this after you have
finished with the handle, or else you will get leaked file
descriptors. *)
val close : t -> unit IO.t
val close : t -> unit Io.t

(** Calls [connect], passes the DB handle to the callback, then calls
[close]. This is the preferred way to use this library since it cleans up
Expand All @@ -50,32 +50,32 @@ module type S = sig
-> ?unix_domain_socket_dir:string
-> ?verbose:int
-> ?max_message_length:int
-> (t -> 'a IO.t)
-> 'a IO.t
-> (t -> 'a Io.t)
-> 'a Io.t

(** Ping the database. If the database is not available, some sort of
exception will be thrown. *)
val ping : t -> unit IO.t
val ping : t -> unit Io.t

(** This function is a wrapper of [ping] that returns a boolean instead of
raising an exception. *)
val alive : t -> bool IO.t
val alive : t -> bool Io.t

(** Start a transaction. *)
val begin_work
: ?isolation:Isolation.t
-> ?access:Access.t
-> ?deferrable:bool
-> t
-> t IO.t
-> t Io.t

(** Commit a transaction. Throws an exception if no transaction is open.
Use [with_transaction] when possible. *)
val commit : t -> unit IO.t
val commit : t -> unit Io.t

(** Rollback a transaction. Throws an exception if no transaction is open.
Use [with_transaction] when possible. *)
val rollback : t -> unit IO.t
val rollback : t -> unit Io.t

(** [with_transaction db ?isolation ?access ?deferrable f] wraps your
function [f] inside a transactional block.
Expand All @@ -89,8 +89,8 @@ module type S = sig
-> ?access:Access.t
-> ?deferrable:bool
-> t
-> (t -> 'b IO.t)
-> 'b IO.t
-> (t -> 'b Io.t)
-> 'b Io.t

module Prepared : sig
type s [@@deriving sexp_of]
Expand All @@ -99,20 +99,20 @@ module type S = sig
sets the parameter types to [types].
If no [name] is given, a random name will be generated.
If no types are given, then the PostgreSQL engine infers types. *)
val prepare : ?name:string -> ?types:oid list -> t -> query:string -> s IO.t
val prepare : ?name:string -> ?types:oid list -> t -> query:string -> s Io.t

(** [close_statement t] closes a prepared statement and frees
up any resources. *)
val close : s -> unit IO.t
val close : s -> unit Io.t

(** [prepare] a query, execute [f], and then [close_statement] *)
val with_prepare
: ?name:string
-> ?types:oid list
-> t
-> query:string
-> f:(s -> 'a IO.t)
-> 'a IO.t
-> f:(s -> 'a Io.t)
-> 'a Io.t

(** [execute conn ~params t] executes the given prepared statement, with
the given parameters [params], returning the result rows (if any).
Expand All @@ -127,87 +127,87 @@ module type S = sig
created in step (1) above (otherwise the unnamed portal is used).
This is only important if you want to call {!describe_portal}
to find out the result types. *)
val execute : ?portal:string -> s -> params:param list -> row list IO.t
val execute : ?portal:string -> s -> params:param list -> row list Io.t

(** [execute_unit ?portal s ?params] same as execute, but intended
for database calls that have side-affects rather than returning results *)
val execute_unit : ?portal:string -> s -> params:param list -> unit IO.t
val execute_unit : ?portal:string -> s -> params:param list -> unit Io.t

val execute_fold
: ?portal:string
-> s
-> params:param list
-> init:'accum
-> f:('accum -> row -> 'accum IO.t)
-> 'accum IO.t
-> f:('accum -> row -> 'accum Io.t)
-> 'accum Io.t

val execute_iter
: ?portal:string
-> s
-> params:param list
-> f:(row -> unit IO.t)
-> unit IO.t
-> f:(row -> unit Io.t)
-> unit Io.t

val execute_map
: ?portal:string
-> s
-> params:param list
-> f:(row -> 'a IO.t)
-> 'a list IO.t
-> f:(row -> 'a Io.t)
-> 'a list Io.t

val execute_many : s -> params:param list list -> row list list IO.t
val execute_many : s -> params:param list list -> row list list Io.t

(** [describe_statement t] describes the statement's parameter types and
result types. *)
val describe : s -> (params_description * Result_desc.t list option) IO.t
val describe : s -> (params_description * Result_desc.t list option) Io.t

(** [close_portal conn ?portal ()] closes a portal and frees up any
resources. *)
val close_portal : ?portal:string -> s -> unit IO.t
val close_portal : ?portal:string -> s -> unit Io.t

(** [describe_portal conn ?portal ()] describes the named or unnamed
portal's result types. *)
val describe_portal : ?portal:string -> s -> Result_desc.t list option IO.t
val describe_portal : ?portal:string -> s -> Result_desc.t list option Io.t
end

(** [execute conn ?params query] prepares and executes the statement
[query] and returns the result. *)
val execute : ?params:row -> t -> string -> row list IO.t
val execute : ?params:row -> t -> string -> row list Io.t

(** [execute_unit conn ?params query ] same as execute, but intended
for database calls that have side-affects rather than returning results *)
val execute_unit : ?params:row -> t -> string -> unit IO.t
val execute_unit : ?params:row -> t -> string -> unit Io.t

val execute_fold
: ?params:param list
-> t
-> string
-> init:'accum
-> f:('accum -> row -> 'accum IO.t)
-> 'accum IO.t
-> f:('accum -> row -> 'accum Io.t)
-> 'accum Io.t

val execute_map
: ?params:param list
-> t
-> string
-> f:(row -> 'a IO.t)
-> 'a list IO.t
-> f:(row -> 'a Io.t)
-> 'a list Io.t

val execute_iter
: ?params:param list
-> t
-> string
-> f:(row -> unit IO.t)
-> unit IO.t
-> f:(row -> unit Io.t)
-> unit Io.t

(** Prepares a query as in [execute] and then executes it once per set of
parameters in [params]. This is more efficient than calling [execute]
in a loop because the query is only prepared once. *)
val execute_many : t -> query:string -> params:param list list -> row list list IO.t
val execute_many : t -> query:string -> params:param list list -> row list list Io.t

(** [simple_query conn query] executes the command(s) in the given [query]
and returns a list of query results (i.e. if you run two queries, you
will get a list with two elements: the results of the first query
followed by the results of the second query. *)
val simple_query : t -> string -> row list list IO.t
val simple_query : t -> string -> row list list Io.t
end
4 changes: 2 additions & 2 deletions pgx_async/src/pgx_async.mli
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(** Async based Postgres client based on Pgx. *)
open Async_kernel

include Pgx.S with type 'a IO.t = 'a Deferred.t
include Pgx.S with type 'a Io.t = 'a Deferred.t

(* for testing purposes *)
module Thread : Pgx.IO with type 'a t = 'a Deferred.t
module Thread : Pgx.Io with type 'a t = 'a Deferred.t

val with_conn
: ?host:string
Expand Down
32 changes: 16 additions & 16 deletions pgx_lwt/src/pgx_lwt.ml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
module IO_intf = Io_intf
module Io_intf = Io_intf

module type S = Pgx.S with type 'a IO.t = 'a Lwt.t
module type S = Pgx.S with type 'a Io.t = 'a Lwt.t

module Thread = struct
open Lwt

module Make (IO : IO_intf.S) = struct
module Make (Io : Io_intf.S) = struct
type 'a t = 'a Lwt.t

let return = return
let ( >>= ) = ( >>= )
let catch = catch

type sockaddr = IO.sockaddr =
type sockaddr = Io.sockaddr =
| Unix of string
| Inet of string * int

type in_channel = IO.in_channel
type out_channel = IO.out_channel
type in_channel = Io.in_channel
type out_channel = Io.out_channel

let output_char = IO.output_char
let output_string = IO.output_string
let output_char = Io.output_char
let output_string = Io.output_string

let output_binary_int w n =
let chr = Char.chr in
Expand All @@ -32,9 +32,9 @@ module Thread = struct
>>= fun () -> output_char w (chr (n land 255))
;;

let flush = IO.flush
let input_char = IO.input_char
let really_input = IO.really_input
let flush = Io.flush
let input_char = Io.input_char
let really_input = Io.really_input

let input_binary_int r =
let b = Bytes.create 4 in
Expand All @@ -45,9 +45,9 @@ module Thread = struct
(code s.[0] lsl 24) lor (code s.[1] lsl 16) lor (code s.[2] lsl 8) lor code s.[3]
;;

let close_in = IO.close_in
let open_connection = IO.open_connection
let getlogin = IO.getlogin
let close_in = Io.close_in
let open_connection = Io.open_connection
let getlogin = Io.getlogin
let debug s = Logs_lwt.debug (fun m -> m "%s" s)
let protect f ~finally = Lwt.finalize f finally

Expand All @@ -61,7 +61,7 @@ module Thread = struct
end
end

module Make (IO : IO_intf.S) = struct
module Thread = Thread.Make (IO)
module Make (Io : Io_intf.S) = struct
module Thread = Thread.Make (Io)
include Pgx.Make (Thread)
end
6 changes: 3 additions & 3 deletions pgx_lwt/src/pgx_lwt.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module IO_intf = Io_intf
module Io_intf = Io_intf

module type S = Pgx.S with type 'a IO.t = 'a Lwt.t
module type S = Pgx.S with type 'a Io.t = 'a Lwt.t

module Make (IO : Io_intf.S) : S
module Make (Io : Io_intf.S) : S
2 changes: 1 addition & 1 deletion pgx_lwt_mirage/src/pgx_lwt_mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct
let connect stack =
let open_connection = connect_stack stack in
(module struct
module T : Pgx_lwt.IO_intf.S = struct
module T : Pgx_lwt.Io_intf.S = struct
include Thread

let open_connection = open_connection
Expand Down
2 changes: 1 addition & 1 deletion pgx_lwt_unix/src/pgx_lwt_unix.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Lwt

module Thread : Pgx_lwt.IO_intf.S = struct
module Thread : Pgx_lwt.Io_intf.S = struct
type sockaddr =
| Unix of string
| Inet of string * int
Expand Down
4 changes: 2 additions & 2 deletions pgx_test/src/pgx_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ let check_results = Alcotest.(check (list (list (list (option string)))))

module Make_tests
(Pgx_impl : Pgx.S)
(Alcotest_io : ALCOTEST_IO with type 'a monad := 'a Pgx_impl.IO.t) =
(Alcotest_io : ALCOTEST_IO with type 'a monad := 'a Pgx_impl.Io.t) =
struct
open Pgx_impl.IO
open Pgx_impl.Io
open Pgx_impl

let default_database = "postgres"
Expand Down
2 changes: 1 addition & 1 deletion pgx_test/src/pgx_test.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ end

module Make_tests
(Pgx_impl : Pgx.S)
(Alcotest_io : ALCOTEST_IO with type 'a monad := 'a Pgx_impl.IO.t) : S
(Alcotest_io : ALCOTEST_IO with type 'a monad := 'a Pgx_impl.Io.t) : S
4 changes: 2 additions & 2 deletions pgx_unix/src/pgx_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Boston, MA 02111-1307, USA.
*)

include Pgx.S with type 'a IO.t = 'a
include Pgx.S with type 'a Io.t = 'a

(* for testing purposes *)
module Simple_thread : Pgx.IO with type 'a t = 'a
module Simple_thread : Pgx.Io with type 'a t = 'a

0 comments on commit 11c3adf

Please sign in to comment.