refactor: Move hasql helpers to Common module

This commit is contained in:
steve-chavez
2019-10-08 12:41:39 -05:00
committed by Steve Chávez
parent 1173bc277b
commit f2b126f147
6 changed files with 49 additions and 48 deletions
+2 -1
View File
@@ -40,7 +40,8 @@ library
PostgREST.RangeQuery
PostgREST.Types
other-modules: Paths_postgrest
PostgREST.QueryBuilder.Private
PostgREST.Private.Common
PostgREST.Private.QueryFragment
hs-source-dirs: src
build-depends: base >= 4.9 && < 4.13
, HTTP >= 4000.3.7 && < 4000.4
+1 -12
View File
@@ -40,21 +40,10 @@ import Unsafe (unsafeHead)
import Control.Applicative
import PostgREST.Private.Common
import PostgREST.Types
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 pgVer = do
HT.sql "set local schema ''" -- for getting the fully qualified name(schema.name) of every db object
+22
View File
@@ -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 #-}
{-|
Module : PostgREST.QueryBuilder.Private
Module : PostgREST.Private.QueryFragment
Description : Helper functions for PostgREST.QueryBuilder.
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 Data.Maybe
+1 -1
View File
@@ -27,7 +27,7 @@ import Data.Tree (Tree (..))
import Data.Maybe
import PostgREST.QueryBuilder.Private
import PostgREST.Private.QueryFragment
import PostgREST.RangeQuery (allRange, rangeLimit,
rangeOffset)
import PostgREST.Types
+6 -17
View File
@@ -22,16 +22,19 @@ import Data.Aeson as JSON
import qualified Data.Aeson.Lens as L
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Text (intercalate, unwords)
import Data.Text (intercalate,
unwords)
import Data.Text.Encoding (encodeUtf8)
import qualified Hasql.Decoders as HD
import qualified Hasql.Encoders as HE
import qualified Hasql.Statement as H
import PostgREST.ApiRequest (PreferRepresentation (..))
import PostgREST.QueryBuilder.Private
import PostgREST.Private.Common
import PostgREST.Private.QueryFragment
import PostgREST.Types
import Protolude hiding (cast,
intercalate, replace)
intercalate,
replace)
import Text.InterpolatedString.Perl6 (qc)
{-| The generic query result format used by API responses. The location header
@@ -187,17 +190,3 @@ createExplainStatement countQuery =
unicodeStatement :: Text -> HE.Params a -> HD.Result b -> Bool -> H.Statement a b
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