Merge branch 'master' of https://github.com/begriffs/postgrest
This commit is contained in:
@@ -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:
|
||||
|
||||
+2
-1
@@ -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
|
||||
@@ -139,6 +139,7 @@ Test-Suite spec
|
||||
, Feature.DeleteSpec
|
||||
, Feature.InsertSpec
|
||||
, Feature.QuerySpec
|
||||
, Feature.QueryLimitedSpec
|
||||
, Feature.RangeSpec
|
||||
, Feature.StructureSpec
|
||||
, Paths_postgrest
|
||||
|
||||
+45
-45
@@ -1,70 +1,71 @@
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
--module PostgREST.App where
|
||||
module PostgREST.App (
|
||||
handleRequest
|
||||
postgrest
|
||||
) where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Arrow ((***))
|
||||
import Control.Monad (join)
|
||||
import Data.Bifunctor (first)
|
||||
import Data.List (delete, find, sortBy)
|
||||
import Data.Maybe (fromJust, fromMaybe,
|
||||
isJust, mapMaybe)
|
||||
import Data.Ord (comparing)
|
||||
import Data.Ranged.Ranges (emptyRange)
|
||||
import Data.String.Conversions (cs)
|
||||
import Data.Text (Text, replace, strip)
|
||||
import Data.Time.Clock.POSIX (getPOSIXTime)
|
||||
import Control.Arrow ((***))
|
||||
import Control.Monad (join)
|
||||
import Data.Bifunctor (first)
|
||||
import Data.List (find, sortBy, delete)
|
||||
import Data.Maybe (isJust, fromMaybe, fromJust, mapMaybe)
|
||||
import Data.Ord (comparing)
|
||||
import Data.Ranged.Ranges (emptyRange)
|
||||
import Data.String.Conversions (cs)
|
||||
import Data.Text (Text, replace, strip)
|
||||
import Data.Tree
|
||||
|
||||
import Text.Parsec.Error
|
||||
import Text.ParserCombinators.Parsec (parse)
|
||||
import qualified Hasql.Pool as P
|
||||
import qualified Hasql.Transaction as HT
|
||||
|
||||
import Network.HTTP.Base (urlEncodeVars)
|
||||
import Text.Parsec.Error
|
||||
import Text.ParserCombinators.Parsec (parse)
|
||||
|
||||
import Network.HTTP.Base (urlEncodeVars)
|
||||
import Network.HTTP.Types.Header
|
||||
import Network.HTTP.Types.Status
|
||||
import Network.HTTP.Types.URI (parseSimpleQuery)
|
||||
import Network.HTTP.Types.URI (parseSimpleQuery)
|
||||
import Network.Wai
|
||||
import Network.Wai.Middleware.RequestLogger (logStdout)
|
||||
|
||||
import qualified Hasql.Pool as P
|
||||
|
||||
import Data.Aeson
|
||||
import Data.Aeson.Types (emptyArray)
|
||||
import Data.Aeson.Types (emptyArray)
|
||||
import Data.Monoid
|
||||
import qualified Data.Vector as V
|
||||
import qualified Hasql.Transaction as H
|
||||
import qualified Hasql.Transaction as HT
|
||||
import PostgREST.ApiRequest (Action (..),
|
||||
ApiRequest (..),
|
||||
ContentType (..), PreferRepresentation (..),
|
||||
Target (..),
|
||||
userApiRequest)
|
||||
import PostgREST.Auth (tokenJWT)
|
||||
import PostgREST.Config (AppConfig (..))
|
||||
import Data.Time.Clock.POSIX (getPOSIXTime)
|
||||
import qualified Data.Vector as V
|
||||
import qualified Hasql.Transaction as H
|
||||
|
||||
import PostgREST.ApiRequest (ApiRequest(..), ContentType(..)
|
||||
, Action(..), Target(..)
|
||||
, PreferRepresentation (..)
|
||||
, userApiRequest)
|
||||
import PostgREST.Auth (tokenJWT)
|
||||
import PostgREST.Config (AppConfig (..))
|
||||
import PostgREST.DbStructure
|
||||
import PostgREST.Error (errResponse,
|
||||
pgErrResponse)
|
||||
import PostgREST.Middleware
|
||||
import PostgREST.Error (errResponse, pgErrResponse)
|
||||
import PostgREST.Parsers
|
||||
import PostgREST.RangeQuery
|
||||
import PostgREST.Middleware
|
||||
import PostgREST.QueryBuilder ( callProc
|
||||
, addJoinConditions
|
||||
, sourceCTEName
|
||||
, requestToQuery
|
||||
, requestToCountQuery
|
||||
, addRelations
|
||||
, createReadStatement
|
||||
, createWriteStatement
|
||||
, ResultsWithCount
|
||||
)
|
||||
import PostgREST.Types
|
||||
|
||||
import PostgREST.QueryBuilder (ResultsWithCount,
|
||||
addJoinConditions,
|
||||
addRelations, callProc,
|
||||
createReadStatement,
|
||||
createWriteStatement,
|
||||
requestToCountQuery,
|
||||
requestToQuery,
|
||||
sourceCTEName)
|
||||
|
||||
import Prelude
|
||||
|
||||
handleRequest :: AppConfig -> DbStructure -> P.Pool -> Application
|
||||
handleRequest 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
|
||||
@@ -76,7 +77,6 @@ handleRequest conf dbStructure pool =
|
||||
(HT.run handleReq HT.ReadCommitted HT.Write)
|
||||
respond resp
|
||||
|
||||
|
||||
app :: DbStructure -> AppConfig -> RequestBody -> Request -> H.Transaction Response
|
||||
app dbStructure conf reqBody req =
|
||||
let
|
||||
|
||||
+19
-18
@@ -3,29 +3,30 @@
|
||||
module Main where
|
||||
|
||||
|
||||
import PostgREST.App (handleRequest)
|
||||
import PostgREST.Config (AppConfig (..), minimumPgVersion,
|
||||
prettyVersion, readOptions)
|
||||
import PostgREST.App
|
||||
import PostgREST.Config (AppConfig (..),
|
||||
minimumPgVersion,
|
||||
prettyVersion,
|
||||
readOptions)
|
||||
import PostgREST.DbStructure
|
||||
|
||||
import Control.Monad
|
||||
import Data.Monoid ((<>))
|
||||
import Data.String.Conversions (cs)
|
||||
|
||||
import qualified Hasql.Decoders as HD
|
||||
import qualified Hasql.Encoders as HE
|
||||
import qualified Hasql.Pool as P
|
||||
import qualified Hasql.Query as H
|
||||
import qualified Hasql.Session as H
|
||||
import Data.Monoid ((<>))
|
||||
import Data.String.Conversions (cs)
|
||||
import qualified Hasql.Query as H
|
||||
import qualified Hasql.Session as H
|
||||
import qualified Hasql.Decoders as HD
|
||||
import qualified Hasql.Encoders as HE
|
||||
import qualified Hasql.Pool as P
|
||||
import Network.Wai.Handler.Warp
|
||||
|
||||
import System.IO (BufferMode (..), hSetBuffering,
|
||||
stderr, stdin, stdout)
|
||||
import Web.JWT (secret)
|
||||
import System.IO (BufferMode (..),
|
||||
hSetBuffering, stderr,
|
||||
stdin, stdout)
|
||||
import Web.JWT (secret)
|
||||
#ifndef mingw32_HOST_OS
|
||||
import Control.Concurrent (myThreadId)
|
||||
import Control.Exception.Base (AsyncException (..), throwTo)
|
||||
import System.Posix.Signals
|
||||
import Control.Concurrent (myThreadId)
|
||||
import Control.Exception.Base (throwTo, AsyncException(..))
|
||||
#endif
|
||||
|
||||
isServerVersionSupported :: H.Session Bool
|
||||
@@ -73,4 +74,4 @@ main = do
|
||||
getDbStructure (cs $ configSchema conf)
|
||||
|
||||
let dbStructure = either (error.show) id result
|
||||
runSettings appSettings $ handleRequest conf dbStructure pool
|
||||
runSettings appSettings $ postgrest conf dbStructure pool
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+8
-8
@@ -1,13 +1,13 @@
|
||||
module Main where
|
||||
|
||||
import SpecHelper
|
||||
import Test.Hspec
|
||||
import Test.Hspec
|
||||
import SpecHelper
|
||||
|
||||
import qualified Hasql.Pool as P
|
||||
import qualified Hasql.Pool as P
|
||||
|
||||
import Data.String.Conversions (cs)
|
||||
import PostgREST.App (handleRequest)
|
||||
import PostgREST.DbStructure (getDbStructure)
|
||||
import PostgREST.DbStructure (getDbStructure)
|
||||
import PostgREST.App (postgrest)
|
||||
import Data.String.Conversions (cs)
|
||||
|
||||
import qualified Feature.AuthSpec
|
||||
import qualified Feature.ConcurrentSpec
|
||||
@@ -27,8 +27,8 @@ main = do
|
||||
|
||||
result <- P.use pool $ getDbStructure "test"
|
||||
let dbStructure = either (error.show) id result
|
||||
withApp = return $ handleRequest testCfg dbStructure pool
|
||||
ltdApp = return $ handleRequest testLtdRowsCfg dbStructure pool
|
||||
withApp = return $ postgrest testCfg dbStructure pool
|
||||
ltdApp = return $ postgrest testLtdRowsCfg dbStructure pool
|
||||
|
||||
hspec $ do
|
||||
mapM_ (beforeAll_ resetDb . before withApp) specs
|
||||
|
||||
Reference in New Issue
Block a user