File tree Expand file tree Collapse file tree 3 files changed +47
-47
lines changed
Expand file tree Collapse file tree 3 files changed +47
-47
lines changed Original file line number Diff line number Diff line change 1+ {-# LANGUAGE DataKinds #-}
2+ {-# LANGUAGE ImplicitParams #-}
3+ {-# LANGUAGE OverloadedStrings #-}
4+
15module Main (main ) where
26
3- import Clinic qualified
7+ import Clinic.API (app )
8+ import Clinic.Database (migrate' )
9+
10+ import Control.Monad.Logger (NoLoggingT (runNoLoggingT ))
11+
12+ import Data.ByteString (ByteString )
13+ import Data.Kind (Type )
14+
15+ import Database.Persist.Postgresql (createPostgresqlPool )
16+
17+ import Network.Wai.Handler.Warp (run )
18+
19+ import Options.Generic
20+
21+ type Opts :: Type -> Type
22+ data Opts w = MkOpts
23+ { port :: ! (w ::: Int <?> " Port to listen on" <!> " 8080" <#> " p" )
24+ , dbUrl :: ! (w ::: ByteString <?> " Database connection string" <#> " u" )
25+ , dbPoolSize :: ! (w ::: Int <?> " Database pool size" <!> " 10" <#> " s" )
26+ }
27+ deriving stock (Generic )
28+
29+ deriving anyclass instance ParseRecord (Opts Wrapped )
30+ deriving stock instance Show (Opts Unwrapped )
431
532main :: IO ()
6- main = Clinic. main
33+ main = do
34+ (opts :: Opts Unwrapped ) <- unwrapRecord " Clinic API"
35+ pool <- runNoLoggingT $ createPostgresqlPool opts. dbUrl opts. dbPoolSize
36+ let ? pool = pool
37+ migrate'
38+ run opts. port app
Original file line number Diff line number Diff line change @@ -31,14 +31,10 @@ library
3131
3232 build-depends :
3333 , aeson
34- , base ^>= 4.17.2.1
35- , bytestring
34+ , base ^>= 4.17.2.1
3635 , esqueleto
37- , monad-logger
3836 , mtl
39- , optparse-generic
4037 , persistent
41- , persistent-postgresql
4238 , resource-pool
4339 , servant
4440 , servant-server
@@ -47,16 +43,20 @@ library
4743 , time
4844 , transformers
4945 , unliftio
50- , warp
5146
5247 hs-source-dirs : src
5348
5449executable clinic
5550 import : defaults, warnings
5651 main-is : Main.hs
5752 build-depends :
58- , base ^>= 4.17.2.1
53+ , base ^>= 4.17.2.1
54+ , bytestring
5955 , clinic
56+ , monad-logger
57+ , optparse-generic
58+ , persistent-postgresql
59+ , warp
6060
6161 hs-source-dirs : app
6262
Original file line number Diff line number Diff line change 1- {-# LANGUAGE DataKinds #-}
2- {-# LANGUAGE ImplicitParams #-}
3- {-# LANGUAGE OverloadedStrings #-}
1+ module Clinic (
2+ module Clinic.API ,
3+ module Clinic.Database ,
4+ ) where
45
5- module Clinic (main ) where
6-
7- import Clinic.API (app )
8- import Clinic.Database (migrate' )
9-
10- import Control.Monad.Logger (NoLoggingT (runNoLoggingT ))
11-
12- import Data.Kind (Type )
13-
14- import Database.Persist.Postgresql (createPostgresqlPool )
15-
16- import Network.Wai.Handler.Warp (run )
17-
18- import Options.Generic
19-
20- import Data.ByteString (ByteString )
21-
22- type Opts :: Type -> Type
23- data Opts w = MkOpts
24- { port :: ! (w ::: Int <?> " Port to listen on" <!> " 8080" <#> " p" )
25- , dbUrl :: ! (w ::: ByteString <?> " Database connection string" <#> " u" )
26- , dbPoolSize :: ! (w ::: Int <?> " Database pool size" <!> " 10" <#> " s" )
27- }
28- deriving stock (Generic )
29-
30- deriving anyclass instance ParseRecord (Opts Wrapped )
31- deriving stock instance Show (Opts Unwrapped )
32-
33- main :: IO ()
34- main = do
35- (opts :: Opts Unwrapped ) <- unwrapRecord " Clinic API"
36- pool <- runNoLoggingT $ createPostgresqlPool opts. dbUrl opts. dbPoolSize
37- let ? pool = pool
38- migrate'
39- run opts. port app
6+ import Clinic.API
7+ import Clinic.Database
You can’t perform that action at this time.
0 commit comments