generated from tpl/purs
Fix warnings. Add trivial helpers for queries with no input.
This commit is contained in:
parent
d2765285e4
commit
0019baea2f
@ -12,10 +12,13 @@ module Database.PostgreSQL.Aff
|
|||||||
, withTransaction
|
, withTransaction
|
||||||
, command
|
, command
|
||||||
, execute
|
, execute
|
||||||
|
, execute'
|
||||||
, fromClient
|
, fromClient
|
||||||
, fromPool
|
, fromPool
|
||||||
, query
|
, query
|
||||||
|
, query'
|
||||||
, scalar
|
, scalar
|
||||||
|
, scalar'
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
@ -60,6 +63,7 @@ fromClient :: Client -> Connection
|
|||||||
fromClient client = Connection (Right client)
|
fromClient client = Connection (Right client)
|
||||||
|
|
||||||
-- | PostgreSQL query with parameter (`$1`, `$2`, …) and return types.
|
-- | PostgreSQL query with parameter (`$1`, `$2`, …) and return types.
|
||||||
|
newtype Query ∷ ∀ ik ok. ik → ok → Type
|
||||||
newtype Query i o
|
newtype Query i o
|
||||||
= Query String
|
= Query String
|
||||||
|
|
||||||
@ -176,6 +180,13 @@ execute ::
|
|||||||
Aff (Maybe PGError)
|
Aff (Maybe PGError)
|
||||||
execute conn (Query sql) values = either Just (const $ Nothing) <$> unsafeQuery conn sql (toSQLRow values)
|
execute conn (Query sql) values = either Just (const $ Nothing) <$> unsafeQuery conn sql (toSQLRow values)
|
||||||
|
|
||||||
|
execute' ::
|
||||||
|
forall o.
|
||||||
|
Connection ->
|
||||||
|
Query Row0 o ->
|
||||||
|
Aff (Maybe PGError)
|
||||||
|
execute' conn (Query sql) = either Just (const $ Nothing) <$> unsafeQuery conn sql (toSQLRow Row0)
|
||||||
|
|
||||||
-- | Execute a PostgreSQL query and return its results.
|
-- | Execute a PostgreSQL query and return its results.
|
||||||
query ::
|
query ::
|
||||||
forall i o.
|
forall i o.
|
||||||
@ -189,6 +200,17 @@ query conn (Query sql) values = do
|
|||||||
r <- unsafeQuery conn sql (toSQLRow values)
|
r <- unsafeQuery conn sql (toSQLRow values)
|
||||||
pure $ r >>= _.rows >>> traverse (fromSQLRow >>> lmap ConversionError)
|
pure $ r >>= _.rows >>> traverse (fromSQLRow >>> lmap ConversionError)
|
||||||
|
|
||||||
|
query' ::
|
||||||
|
forall i o.
|
||||||
|
ToSQLRow i =>
|
||||||
|
FromSQLRow o =>
|
||||||
|
Connection ->
|
||||||
|
Query Row0 o ->
|
||||||
|
Aff (Either PGError (Array o))
|
||||||
|
query' conn (Query sql) = do
|
||||||
|
r <- unsafeQuery conn sql (toSQLRow Row0)
|
||||||
|
pure $ r >>= _.rows >>> traverse (fromSQLRow >>> lmap ConversionError)
|
||||||
|
|
||||||
-- | Execute a PostgreSQL query and return the first field of the first row in
|
-- | Execute a PostgreSQL query and return the first field of the first row in
|
||||||
-- | the result.
|
-- | the result.
|
||||||
scalar ::
|
scalar ::
|
||||||
@ -201,6 +223,14 @@ scalar ::
|
|||||||
Aff (Either PGError (Maybe o))
|
Aff (Either PGError (Maybe o))
|
||||||
scalar conn sql values = query conn sql values <#> map (head >>> map (case _ of Row1 a -> a))
|
scalar conn sql values = query conn sql values <#> map (head >>> map (case _ of Row1 a -> a))
|
||||||
|
|
||||||
|
scalar' ::
|
||||||
|
forall o.
|
||||||
|
FromSQLValue o =>
|
||||||
|
Connection ->
|
||||||
|
Query Row0 (Row1 o) ->
|
||||||
|
Aff (Either PGError (Maybe o))
|
||||||
|
scalar' conn sql = query conn sql Row0 <#> map (head >>> map (case _ of Row1 a -> a))
|
||||||
|
|
||||||
-- | Execute a PostgreSQL query and return its command tag value
|
-- | Execute a PostgreSQL query and return its command tag value
|
||||||
-- | (how many rows were affected by the query). This may be useful
|
-- | (how many rows were affected by the query). This may be useful
|
||||||
-- | for example with `DELETE` or `UPDATE` queries.
|
-- | for example with `DELETE` or `UPDATE` queries.
|
||||||
|
@ -41,6 +41,6 @@ load = do
|
|||||||
env ← liftEffect $ getEnv <#> (Object.toUnfoldable ∷ _ → Array _) >>> Map.fromFoldable
|
env ← liftEffect $ getEnv <#> (Object.toUnfoldable ∷ _ → Array _) >>> Map.fromFoldable
|
||||||
runValidator validator env >>= un V
|
runValidator validator env >>= un V
|
||||||
>>> case _ of
|
>>> case _ of
|
||||||
Left err → do
|
Left _ → do
|
||||||
throwError $ error "Configuration error. Please verify your environment and .env file."
|
throwError $ error "Configuration error. Please verify your environment and .env file."
|
||||||
Right p → pure p
|
Right p → pure p
|
||||||
|
Loading…
Reference in New Issue
Block a user