From 21e2ea213c371ad3e6aeb2976b755915c3a7a90e Mon Sep 17 00:00:00 2001 From: Lorenzo Manacorda Date: Tue, 10 Dec 2024 13:28:29 +0100 Subject: [PATCH] example/h-sql: move arguments to top IMO, this improves the examples by: - making the arguments stand out more, by moving them to the top - removing visual clutter from the promise section, which is the focus of the example --- example/h-sql/README.md | 14 ++++++-------- example/h-sql/sql.eml.ml | 12 +++++------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/example/h-sql/README.md b/example/h-sql/README.md index 9b518989..0e32bc71 100644 --- a/example/h-sql/README.md +++ b/example/h-sql/README.md @@ -15,22 +15,20 @@ a library for talking to SQL databases: module type DB = Caqti_lwt.CONNECTION module T = Caqti_type -let list_comments = +let list_comments (module Db : DB) = let query = let open Caqti_request.Infix in - (T.unit ->* T.(tup2 int string)) + (T.unit ->* T.(t2 int string)) "SELECT id, text FROM comment" in - fun (module Db : DB) -> - Lwt.bind (Db.collect_list query ()) Caqti_lwt.or_fail + Lwt.bind (Db.collect_list query ()) Caqti_lwt.or_fail -let add_comment = +let add_comment text (module Db : DB) = let query = let open Caqti_request.Infix in (T.string ->. T.unit) "INSERT INTO comment (text) VALUES ($1)" in - fun text (module Db : DB) -> - let%lwt unit_or_error = Db.exec query text in - Caqti_lwt.or_fail unit_or_error + let%lwt unit_or_error = Db.exec query text in + Caqti_lwt.or_fail unit_or_error let render comments request = diff --git a/example/h-sql/sql.eml.ml b/example/h-sql/sql.eml.ml index 0ef7ef79..66ecc1da 100644 --- a/example/h-sql/sql.eml.ml +++ b/example/h-sql/sql.eml.ml @@ -1,22 +1,20 @@ module type DB = Caqti_lwt.CONNECTION module T = Caqti_type -let list_comments = +let list_comments (module Db : DB) = let query = let open Caqti_request.Infix in (T.unit ->* T.(t2 int string)) "SELECT id, text FROM comment" in - fun (module Db : DB) -> - Lwt.bind (Db.collect_list query ()) Caqti_lwt.or_fail + Lwt.bind (Db.collect_list query ()) Caqti_lwt.or_fail -let add_comment = +let add_comment text (module Db : DB) = let query = let open Caqti_request.Infix in (T.string ->. T.unit) "INSERT INTO comment (text) VALUES ($1)" in - fun text (module Db : DB) -> - let%lwt unit_or_error = Db.exec query text in - Caqti_lwt.or_fail unit_or_error + let%lwt unit_or_error = Db.exec query text in + Caqti_lwt.or_fail unit_or_error let render comments request =