Skip to content

Commit

Permalink
example/h-sql: document Lwt.bind
Browse files Browse the repository at this point in the history
  • Loading branch information
asymmetric committed Dec 10, 2024
1 parent da94944 commit bc5f754
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions example/h-sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ prepared statements using
[Caqti](https://paurkedal.github.io/ocaml-caqti/caqti/Caqti_connect_sig/module-type-S/module-type-CONNECTION/index.html),
a library for talking to SQL databases:

> [!TIP]
> `let%lwt` is syntactic sugar for `Lwt.bind`, so the two forms below are equivalent (a third option would be using `>>=`).
>
> For more information, see [here](https://ocsigen.org/lwt/latest/api/Lwt#3_Callbacks).
```ocaml
module type DB = Caqti_lwt.CONNECTION
module T = Caqti_type
Expand All @@ -17,8 +22,7 @@ let list_comments =
(T.unit ->* T.(tup2 int string))
"SELECT id, text FROM comment" in
fun (module Db : DB) ->
let%lwt comments_or_error = Db.collect_list query () in
Caqti_lwt.or_fail comments_or_error
Lwt.bind (Db.collect_list query ()) Caqti_lwt.or_fail
let add_comment =
let query =
Expand Down
3 changes: 1 addition & 2 deletions example/h-sql/sql.eml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ let list_comments =
(T.unit ->* T.(t2 int string))
"SELECT id, text FROM comment" in
fun (module Db : DB) ->
let%lwt comments_or_error = Db.collect_list query () in
Caqti_lwt.or_fail comments_or_error
Lwt.bind (Db.collect_list query ()) Caqti_lwt.or_fail

let add_comment =
let query =
Expand Down

0 comments on commit bc5f754

Please sign in to comment.