refactor: Move hasql helpers to Common module
This commit is contained in:
committed by
Steve Chávez
parent
1173bc277b
commit
f2b126f147
+2
-1
@@ -40,7 +40,8 @@ library
|
|||||||
PostgREST.RangeQuery
|
PostgREST.RangeQuery
|
||||||
PostgREST.Types
|
PostgREST.Types
|
||||||
other-modules: Paths_postgrest
|
other-modules: Paths_postgrest
|
||||||
PostgREST.QueryBuilder.Private
|
PostgREST.Private.Common
|
||||||
|
PostgREST.Private.QueryFragment
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
build-depends: base >= 4.9 && < 4.13
|
build-depends: base >= 4.9 && < 4.13
|
||||||
, HTTP >= 4000.3.7 && < 4000.4
|
, HTTP >= 4000.3.7 && < 4000.4
|
||||||
|
|||||||
@@ -40,21 +40,10 @@ import Unsafe (unsafeHead)
|
|||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
|
|
||||||
|
import PostgREST.Private.Common
|
||||||
import PostgREST.Types
|
import PostgREST.Types
|
||||||
import Protolude
|
import Protolude
|
||||||
|
|
||||||
column :: HD.Value a -> HD.Row a
|
|
||||||
column = HD.column . HD.nonNullable
|
|
||||||
|
|
||||||
nullableColumn :: HD.Value a -> HD.Row (Maybe a)
|
|
||||||
nullableColumn = HD.column . HD.nullable
|
|
||||||
|
|
||||||
element :: HD.Value a -> HD.Array a
|
|
||||||
element = HD.element . HD.nonNullable
|
|
||||||
|
|
||||||
param :: HE.Value a -> HE.Params a
|
|
||||||
param = HE.param . HE.nonNullable
|
|
||||||
|
|
||||||
getDbStructure :: Schema -> PgVersion -> HT.Transaction DbStructure
|
getDbStructure :: Schema -> PgVersion -> HT.Transaction DbStructure
|
||||||
getDbStructure schema pgVer = do
|
getDbStructure schema pgVer = do
|
||||||
HT.sql "set local schema ''" -- for getting the fully qualified name(schema.name) of every db object
|
HT.sql "set local schema ''" -- for getting the fully qualified name(schema.name) of every db object
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{-|
|
||||||
|
Module : PostgREST.Common
|
||||||
|
Description : Common helper functions.
|
||||||
|
-}
|
||||||
|
module PostgREST.Private.Common where
|
||||||
|
|
||||||
|
import Data.Maybe
|
||||||
|
import qualified Hasql.Decoders as HD
|
||||||
|
import qualified Hasql.Encoders as HE
|
||||||
|
import Protolude
|
||||||
|
|
||||||
|
column :: HD.Value a -> HD.Row a
|
||||||
|
column = HD.column . HD.nonNullable
|
||||||
|
|
||||||
|
nullableColumn :: HD.Value a -> HD.Row (Maybe a)
|
||||||
|
nullableColumn = HD.column . HD.nullable
|
||||||
|
|
||||||
|
element :: HD.Value a -> HD.Array a
|
||||||
|
element = HD.element . HD.nonNullable
|
||||||
|
|
||||||
|
param :: HE.Value a -> HE.Params a
|
||||||
|
param = HE.param . HE.nonNullable
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
{-# LANGUAGE LambdaCase #-}
|
{-# LANGUAGE LambdaCase #-}
|
||||||
{-|
|
{-|
|
||||||
Module : PostgREST.QueryBuilder.Private
|
Module : PostgREST.Private.QueryFragment
|
||||||
Description : Helper functions for PostgREST.QueryBuilder.
|
Description : Helper functions for PostgREST.QueryBuilder.
|
||||||
|
|
||||||
Any function that outputs a SqlFragment should be in this module.
|
Any function that outputs a SqlFragment should be in this module.
|
||||||
-}
|
-}
|
||||||
module PostgREST.QueryBuilder.Private where
|
module PostgREST.Private.QueryFragment where
|
||||||
|
|
||||||
import qualified Data.HashMap.Strict as HM
|
import qualified Data.HashMap.Strict as HM
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
@@ -27,12 +27,12 @@ import Data.Tree (Tree (..))
|
|||||||
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
|
||||||
import PostgREST.QueryBuilder.Private
|
import PostgREST.Private.QueryFragment
|
||||||
import PostgREST.RangeQuery (allRange, rangeLimit,
|
import PostgREST.RangeQuery (allRange, rangeLimit,
|
||||||
rangeOffset)
|
rangeOffset)
|
||||||
import PostgREST.Types
|
import PostgREST.Types
|
||||||
import Protolude hiding (cast, intercalate,
|
import Protolude hiding (cast, intercalate,
|
||||||
replace)
|
replace)
|
||||||
|
|
||||||
readRequestToQuery :: Bool -> ReadRequest -> SqlQuery
|
readRequestToQuery :: Bool -> ReadRequest -> SqlQuery
|
||||||
readRequestToQuery isParent (Node (Select colSelects mainQi tblAlias implJoins logicForest joinConditions_ ordts range, _) forest) =
|
readRequestToQuery isParent (Node (Select colSelects mainQi tblAlias implJoins logicForest joinConditions_ ordts range, _) forest) =
|
||||||
|
|||||||
+17
-28
@@ -17,22 +17,25 @@ module PostgREST.Statements (
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
|
|
||||||
import Control.Lens ((^?))
|
import Control.Lens ((^?))
|
||||||
import Data.Aeson as JSON
|
import Data.Aeson as JSON
|
||||||
import qualified Data.Aeson.Lens as L
|
import qualified Data.Aeson.Lens as L
|
||||||
import qualified Data.ByteString.Char8 as BS
|
import qualified Data.ByteString.Char8 as BS
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.Text (intercalate, unwords)
|
import Data.Text (intercalate,
|
||||||
import Data.Text.Encoding (encodeUtf8)
|
unwords)
|
||||||
import qualified Hasql.Decoders as HD
|
import Data.Text.Encoding (encodeUtf8)
|
||||||
import qualified Hasql.Encoders as HE
|
import qualified Hasql.Decoders as HD
|
||||||
import qualified Hasql.Statement as H
|
import qualified Hasql.Encoders as HE
|
||||||
import PostgREST.ApiRequest (PreferRepresentation (..))
|
import qualified Hasql.Statement as H
|
||||||
import PostgREST.QueryBuilder.Private
|
import PostgREST.ApiRequest (PreferRepresentation (..))
|
||||||
|
import PostgREST.Private.Common
|
||||||
|
import PostgREST.Private.QueryFragment
|
||||||
import PostgREST.Types
|
import PostgREST.Types
|
||||||
import Protolude hiding (cast,
|
import Protolude hiding (cast,
|
||||||
intercalate, replace)
|
intercalate,
|
||||||
import Text.InterpolatedString.Perl6 (qc)
|
replace)
|
||||||
|
import Text.InterpolatedString.Perl6 (qc)
|
||||||
|
|
||||||
{-| The generic query result format used by API responses. The location header
|
{-| The generic query result format used by API responses. The location header
|
||||||
is represented as a list of strings containing variable bindings like
|
is represented as a list of strings containing variable bindings like
|
||||||
@@ -187,17 +190,3 @@ createExplainStatement countQuery =
|
|||||||
|
|
||||||
unicodeStatement :: Text -> HE.Params a -> HD.Result b -> Bool -> H.Statement a b
|
unicodeStatement :: Text -> HE.Params a -> HD.Result b -> Bool -> H.Statement a b
|
||||||
unicodeStatement = H.Statement . encodeUtf8
|
unicodeStatement = H.Statement . encodeUtf8
|
||||||
|
|
||||||
-- Helper hasql functions
|
|
||||||
|
|
||||||
column :: HD.Value a -> HD.Row a
|
|
||||||
column = HD.column . HD.nonNullable
|
|
||||||
|
|
||||||
nullableColumn :: HD.Value a -> HD.Row (Maybe a)
|
|
||||||
nullableColumn = HD.column . HD.nullable
|
|
||||||
|
|
||||||
element :: HD.Value a -> HD.Array a
|
|
||||||
element = HD.element . HD.nonNullable
|
|
||||||
|
|
||||||
param :: HE.Value a -> HE.Params a
|
|
||||||
param = HE.param . HE.nonNullable
|
|
||||||
|
|||||||
Reference in New Issue
Block a user