diff --git a/circle.yml b/circle.yml index 951343ccb..e2475e026 100644 --- a/circle.yml +++ b/circle.yml @@ -9,7 +9,9 @@ dependencies: - createdb -O postgrest_test -U ubuntu postgrest_test override: - stack setup + - rm -fr $(stack path --dist-dir) $(stack path --local-install-root) - stack install hlint packdeps cabal-install + - stack build - stack build --test --no-run-tests test: diff --git a/postgrest.cabal b/postgrest.cabal index 7eb0931ab..760500073 100644 --- a/postgrest.cabal +++ b/postgrest.cabal @@ -26,7 +26,7 @@ executable postgrest default-extensions: OverloadedStrings, ScopedTypeVariables, QuasiQuotes ghc-options: -threaded -rtsopts -with-rtsopts=-N default-language: Haskell2010 - build-depends: aeson >= 0.8 && < 0.10 + build-depends: aeson (>= 0.8 && < 0.10) || (>= 0.11 && < 0.12) , base >= 4.8 && < 5 , bytestring , case-insensitive @@ -138,6 +138,7 @@ Test-Suite spec , Feature.DeleteSpec , Feature.InsertSpec , Feature.QuerySpec + , Feature.QueryLimitedSpec , Feature.RangeSpec , Feature.StructureSpec , Paths_postgrest @@ -145,7 +146,6 @@ Test-Suite spec , PostgREST.Auth , PostgREST.Config , PostgREST.Error - , PostgREST.Main , PostgREST.Middleware , PostgREST.Parsers , PostgREST.DbStructure diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index 445e6bcdd..44672e09f 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -3,7 +3,7 @@ {-# LANGUAGE TupleSections #-} --module PostgREST.App where module PostgREST.App ( - app + postgrest ) where import Control.Applicative @@ -18,6 +18,9 @@ import Data.String.Conversions (cs) import Data.Text (Text, replace, strip) import Data.Tree +import qualified Hasql.Pool as P +import qualified Hasql.Transaction as HT + import Text.Parsec.Error import Text.ParserCombinators.Parsec (parse) @@ -26,25 +29,26 @@ import Network.HTTP.Types.Header import Network.HTTP.Types.Status import Network.HTTP.Types.URI (parseSimpleQuery) import Network.Wai +import Network.Wai.Middleware.RequestLogger (logStdout) import Data.Aeson import Data.Aeson.Types (emptyArray) import Data.Monoid +import Data.Time.Clock.POSIX (getPOSIXTime) import qualified Data.Vector as V import qualified Hasql.Transaction as H -import PostgREST.Config (AppConfig (..)) -import PostgREST.Parsers -import PostgREST.DbStructure -import PostgREST.RangeQuery import PostgREST.ApiRequest (ApiRequest(..), ContentType(..) , Action(..), Target(..) , PreferRepresentation (..) , userApiRequest) -import PostgREST.Types import PostgREST.Auth (tokenJWT) -import PostgREST.Error (errResponse) - +import PostgREST.Config (AppConfig (..)) +import PostgREST.DbStructure +import PostgREST.Error (errResponse, pgErrResponse) +import PostgREST.Parsers +import PostgREST.RangeQuery +import PostgREST.Middleware import PostgREST.QueryBuilder ( callProc , addJoinConditions , sourceCTEName @@ -55,9 +59,24 @@ import PostgREST.QueryBuilder ( callProc , createWriteStatement , ResultsWithCount ) +import PostgREST.Types import Prelude + +postgrest :: AppConfig -> DbStructure -> P.Pool -> Application +postgrest conf dbStructure pool = + let middle = (if configQuiet conf then id else logStdout) . defaultMiddle in + + middle $ \ req respond -> do + time <- getPOSIXTime + body <- strictRequestBody req + + let handleReq = runWithClaims conf time (app dbStructure conf body) req + resp <- either pgErrResponse id <$> P.use pool + (HT.run handleReq HT.ReadCommitted HT.Write) + respond resp + app :: DbStructure -> AppConfig -> RequestBody -> Request -> H.Transaction Response app dbStructure conf reqBody req = let diff --git a/src/PostgREST/Main.hs b/src/PostgREST/Main.hs index c3aa95563..f7a09fefc 100644 --- a/src/PostgREST/Main.hs +++ b/src/PostgREST/Main.hs @@ -1,6 +1,6 @@ {-# LANGUAGE CPP #-} -module PostgREST.Main where +module Main where import PostgREST.App @@ -9,23 +9,16 @@ import PostgREST.Config (AppConfig (..), prettyVersion, readOptions) import PostgREST.DbStructure -import PostgREST.Error (pgErrResponse) -import PostgREST.Middleware -import PostgREST.Types (DbStructure) import Control.Monad import Data.Monoid ((<>)) import Data.String.Conversions (cs) -import Data.Time.Clock.POSIX (getPOSIXTime) import qualified Hasql.Query as H import qualified Hasql.Session as H -import qualified Hasql.Transaction as HT import qualified Hasql.Decoders as HD import qualified Hasql.Encoders as HE import qualified Hasql.Pool as P -import Network.Wai import Network.Wai.Handler.Warp -import Network.Wai.Middleware.RequestLogger (logStdout) import System.IO (BufferMode (..), hSetBuffering, stderr, stdin, stdout) @@ -82,16 +75,3 @@ main = do let dbStructure = either (error.show) id result runSettings appSettings $ postgrest conf dbStructure pool - -postgrest :: AppConfig -> DbStructure -> P.Pool -> Application -postgrest conf dbStructure pool = - let middle = (if configQuiet conf then id else logStdout) . defaultMiddle in - - middle $ \ req respond -> do - time <- getPOSIXTime - body <- strictRequestBody req - - let handleReq = runWithClaims conf time (app dbStructure conf body) req - resp <- either pgErrResponse id <$> P.use pool - (HT.run handleReq HT.ReadCommitted HT.Write) - respond resp diff --git a/stack.yaml b/stack.yaml index 74f1079af..e0bf3a04d 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-5.0 +resolver: lts-5.5 extra-deps: - Ranged-sets-0.3.0 - bytestring-tree-builder-0.2.5 diff --git a/test/Main.hs b/test/Main.hs index cc52c0fb4..98cdd3c54 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -6,7 +6,7 @@ import SpecHelper import qualified Hasql.Pool as P import PostgREST.DbStructure (getDbStructure) -import PostgREST.Main (postgrest) +import PostgREST.App (postgrest) import Data.String.Conversions (cs) import qualified Feature.AuthSpec