Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 2c45049d authored by Muhammad Zaki's avatar Muhammad Zaki
Browse files

refactor: open caqti module on query and mutation

parent d7a17057
No related branches found
No related tags found
No related merge requests found
module type DB = Caqti_lwt.CONNECTION
module T = Caqti_type
open Caqti_request.Infix
let getenv_with_default key fallback =
Option.value (Sys.getenv_opt key) ~default:fallback
......@@ -16,13 +14,17 @@ let setup_sql_database =
postgres_host postgres_db)
let list_comments =
let query = (T.unit ->* T.(tup2 int string)) "SELECT id, text FROM comment" in
let query =
let open Caqti_request.Infix in
(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
let add_comment =
let mutation =
let open Caqti_request.Infix in
(T.string ->. T.unit) "INSERT INTO comment (text) VALUES ($1)"
in
fun text (module Db : DB) ->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment