summaryrefslogtreecommitdiff
path: root/bin/main.ml
diff options
context:
space:
mode:
authorMateus Cruz <mateuscolvr@gmail.com>2024-02-05 03:31:35 -0300
committerMateus Cruz <mateuscolvr@gmail.com>2024-02-05 03:31:35 -0300
commit5a2f5bf9a12b270e15757df48afeb1c1db5b34b3 (patch)
tree2f1797364d78d935b4eb79269fd6b100fa77ec21 /bin/main.ml
parentf0142aa1c3b4d7c2fd0b70c9e62c1ec033e445c2 (diff)
add db queries
Diffstat (limited to 'bin/main.ml')
-rw-r--r--bin/main.ml14
1 files changed, 10 insertions, 4 deletions
diff --git a/bin/main.ml b/bin/main.ml
index 7e537a7..99cc0e0 100644
--- a/bin/main.ml
+++ b/bin/main.ml
@@ -4,9 +4,9 @@ open! StdLabels
open Eio
open Piaf
-let request_handler Server.{ request; _ } =
+let request_handler ~db_pool Server.{ request; _ } =
match Rinha.Router.match_route request.meth request.target with
- | Some handler -> handler request
+ | Some handler -> handler db_pool request
| None -> Response.create `Not_found
;;
@@ -17,10 +17,16 @@ let () =
@@ fun sw ->
let config =
let interface = Net.Ipaddr.V4.any in
- let port = 3000 in
+ let port = 8080 in
`Tcp (interface, port)
in
let config = Server.Config.create config in
- let server = Server.create ~config request_handler in
+ let db_uri =
+ Uri.make ~scheme:"postgres" ~userinfo:"admin:123" ~host:"db" ~path:"rinha" ()
+ in
+ let db_pool =
+ Result.get_ok @@ Caqti_eio.connect_pool ~sw ~stdenv:(env :> Caqti_eio.stdenv) db_uri
+ in
+ let server = Server.create ~config (request_handler ~db_pool) in
ignore @@ Server.Command.start ~sw env server
;;