summaryrefslogtreecommitdiff
path: root/bin
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
parentf0142aa1c3b4d7c2fd0b70c9e62c1ec033e445c2 (diff)
add db queries
Diffstat (limited to 'bin')
-rw-r--r--bin/dune10
-rw-r--r--bin/main.ml14
2 files changed, 11 insertions, 13 deletions
diff --git a/bin/dune b/bin/dune
index a186150..9c34236 100644
--- a/bin/dune
+++ b/bin/dune
@@ -5,17 +5,9 @@
(:standard -cclib -static -cclib -no-pie))
(libraries
rinha
-
piaf
routes
eio_main
- caqti-driver-postgresql
logs.fmt
fmt.tty
- logs.threaded
- caqti-eio
- caqti
- ppx_rapper_eio)
-
- (preprocess
- (pps ppx_rapper)))
+ logs.threaded))
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
;;