Skip to content

Commit

Permalink
ppx_rapper_eio
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed May 1, 2023
1 parent 6984748 commit d51ad5e
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 14 deletions.
12 changes: 12 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,15 @@
caqti-lwt
lwt
(caqti-type-calendar :with-test)))

(package
(name ppx_rapper_eio)
(synopsis "EIO support for ppx_rapper")
(depends
(ocaml
(>= 4.07))
(ppx_rapper
(= :version))
caqti-eio
eio
(caqti-type-calendar :with-test)))
2 changes: 1 addition & 1 deletion examples/lwt/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(library
(name examples_lwt)
(libraries lwt ppx_rapper_lwt)
(libraries lwt ppx_rapper_lwt caqti-lwt.unix)
(preprocess
(pps ppx_rapper)))
4 changes: 2 additions & 2 deletions examples/lwt/examples_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ let get_something =
(* Examples of creating caqti connections and using them for queries *)
let main_pooled () =
let pool =
Caqti_lwt.connect_pool (Uri.of_string "postgresql://example.com")
Caqti_lwt_unix.connect_pool (Uri.of_string "postgresql://example.com")
|> Result.get_ok
in
Caqti_lwt.Pool.use (get_something ()) pool

let main_not_pooled () =
Caqti_lwt.with_connection
Caqti_lwt_unix.with_connection
(Uri.of_string "postgresql://example.com")
(get_something ())
5 changes: 5 additions & 0 deletions lib-eio/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(library
(name ppx_rapper_eio)
(public_name ppx_rapper_eio)
(wrapped false)
(libraries ppx_rapper.runtime caqti-eio.unix caqti))
8 changes: 8 additions & 0 deletions lib-eio/rapper_helper.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include Rapper.Make_helper (struct
type +'a t = 'a

let return = Fun.id
let map : ('a -> 'b) -> 'a -> 'b = fun f t -> f t

module Stream = Caqti_eio.Stream
end)
4 changes: 4 additions & 0 deletions lib-eio/rapper_helper.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include
Rapper.RAPPER_HELPER
with type 'a future := 'a
and module Stream = Caqti_eio.Stream
8 changes: 2 additions & 6 deletions lib-runtime/rapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ module Internal = struct
type t = Pack : 'a Caqti_type.t * 'a -> t

let empty = Pack (Caqti_type.unit, ())

let add t x (Pack (t', x')) = Pack (Caqti_type.tup2 t' t, (x', x))
end
end
Expand All @@ -54,21 +53,19 @@ module type IO = sig
type +'a t

val return : 'a -> 'a t

val map : ('a -> 'b) -> 'a t -> 'b t

(* Need this for Caqti_connection_sig.S *)
module Stream : Caqti_stream.S with type 'a future := 'a t
module Stream : Caqti_stream_sig.S with type 'a future := 'a t
end

module type RAPPER_HELPER = sig
type +'a future

val map : ('a -> 'b) -> 'a future -> 'b future

val fail : 'e -> ('a, 'e) result future

module Stream : Caqti_stream.S with type 'a future := 'a future
module Stream : Caqti_stream_sig.S with type 'a future := 'a future

module type CONNECTION =
Caqti_connection_sig.S
Expand All @@ -80,7 +77,6 @@ module Make_helper (Io : IO) :
RAPPER_HELPER with type 'a future := 'a Io.t and module Stream = Io.Stream =
struct
let map = Io.map

let fail e = Io.return (Error e)

module Stream = Io.Stream
Expand Down
7 changes: 2 additions & 5 deletions lib-runtime/rapper.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module Internal : sig
type t = Pack : 'a Caqti_type.t * 'a -> t

val empty : t

val add : 'a Caqti_type.t -> 'a -> t -> t
end
end
Expand All @@ -24,21 +23,19 @@ module type IO = sig
type +'a t

val return : 'a -> 'a t

val map : ('a -> 'b) -> 'a t -> 'b t

(* Need this for Caqti_connection_sig.S *)
module Stream : Caqti_stream.S with type 'a future := 'a t
module Stream : Caqti_stream_sig.S with type 'a future := 'a t
end

module type RAPPER_HELPER = sig
type +'a future

val map : ('a -> 'b) -> 'a future -> 'b future

val fail : 'e -> ('a, 'e) result future

module Stream : Caqti_stream.S with type 'a future := 'a future
module Stream : Caqti_stream_sig.S with type 'a future := 'a future

module type CONNECTION =
Caqti_connection_sig.S
Expand Down
33 changes: 33 additions & 0 deletions ppx_rapper_eio.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "3.1.0"
synopsis: "EIO support for ppx_rapper"
maintainer: ["Roddy MacSween <github@roddymacsween.co.uk>"]
authors: ["Roddy MacSween <github@roddymacsween.co.uk>"]
license: "MIT"
homepage: "https://github.com/roddyyaga/ppx_rapper"
doc: "https://github.com/roddyyaga/ppx_rapper"
bug-reports: "https://github.com/roddyyaga/ppx_rapper/issues"
depends: [
"dune" {>= "2.0"}
"ocaml" {>= "4.07"}
"ppx_rapper" {= version}
"caqti-eio"
"eio"
"caqti-type-calendar" {with-test}
]
build: [
["dune" "subst"] {pinned}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/roddyyaga/ppx_rapper.git"

0 comments on commit d51ad5e

Please sign in to comment.