Make tests pass

This commit is contained in:
Tomasz Rybarczyk 2018-12-16 18:35:58 +01:00
parent 6f2b198d02
commit a6deace1cb
3 changed files with 47 additions and 53 deletions

View File

@ -18,7 +18,7 @@ module Test.README where
import Prelude import Prelude
import Database.PostgreSQL (defaultPoolConfiguration, command, execute, newPool, PG, query, Query(Query), withConnection, withTransaction) import Database.PostgreSQL.PG (defaultPoolConfiguration, command, execute, newPool, PG, query, Query(Query), withConnection, withTransaction)
import Database.PostgreSQL.Row (Row0(Row0), Row3(Row3)) import Database.PostgreSQL.Row (Row0(Row0), Row3(Row3))
import Data.Decimal as Decimal import Data.Decimal as Decimal
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))

View File

@ -1,30 +1,26 @@
module Database.PostgreSQL where module Database.PostgreSQL
-- ( module Row ( module Row
-- , module Value , module Value
-- , PG , PGError(..)
-- , PGError(..) , PGErrorDetail
-- , PGErrorDetail , Database
-- , Database , PoolConfiguration
-- , PoolConfiguration , Pool
-- , Pool , Connection
-- , Connection , Query(..)
-- , Query(..) , newPool
-- , newPool , withConnection
-- , withConnection , withTransaction
-- , withTransaction , defaultPoolConfiguration
-- , defaultPoolConfiguration , command
-- , command , execute
-- , execute , query
-- , query , scalar
-- , scalar ) where
-- , onIntegrityError
-- ) where
import Prelude import Prelude
import Control.Monad.Error.Class (catchError, throwError, try) import Control.Monad.Error.Class (catchError, throwError)
import Control.Monad.Except.Trans (ExceptT, except, runExceptT)
import Control.Monad.Trans.Class (lift)
import Data.Array (head) import Data.Array (head)
import Data.Bifunctor (lmap) import Data.Bifunctor (lmap)
import Data.Either (Either(..), either, hush) import Data.Either (Either(..), either, hush)
@ -35,7 +31,7 @@ import Data.Newtype (class Newtype)
import Data.Nullable (Nullable, toMaybe, toNullable) import Data.Nullable (Nullable, toMaybe, toNullable)
import Data.String (Pattern(..)) import Data.String (Pattern(..))
import Data.String as String import Data.String as String
import Data.Traversable (sequence, traverse) import Data.Traversable (traverse)
import Database.PostgreSQL.Row (class FromSQLRow, class ToSQLRow, Row0(..), Row1(..), Row10(..), Row11(..), Row12(..), Row13(..), Row14(..), Row15(..), Row16(..), Row17(..), Row18(..), Row19(..), Row2(..), Row3(..), Row4(..), Row5(..), Row6(..), Row7(..), Row8(..), Row9(..), fromSQLRow, toSQLRow) as Row import Database.PostgreSQL.Row (class FromSQLRow, class ToSQLRow, Row0(..), Row1(..), Row10(..), Row11(..), Row12(..), Row13(..), Row14(..), Row15(..), Row16(..), Row17(..), Row18(..), Row19(..), Row2(..), Row3(..), Row4(..), Row5(..), Row6(..), Row7(..), Row8(..), Row9(..), fromSQLRow, toSQLRow) as Row
import Database.PostgreSQL.Row (class FromSQLRow, class ToSQLRow, Row0(..), Row1(..), fromSQLRow, toSQLRow) import Database.PostgreSQL.Row (class FromSQLRow, class ToSQLRow, Row0(..), Row1(..), fromSQLRow, toSQLRow)
import Database.PostgreSQL.Value (class FromSQLValue) import Database.PostgreSQL.Value (class FromSQLValue)
@ -151,32 +147,30 @@ foreign import ffiConnect
-> Pool -> Pool
-> EffectFnAff (Either PGError ConnectResult) -> EffectFnAff (Either PGError ConnectResult)
-- -- | Run an action within a transaction. The transaction is committed if the -- | Run an action within a transaction. The transaction is committed if the
-- -- | action returns cleanly, and rolled back if the action throws (either a -- | action returns cleanly, and rolled back if the action throws (either a
-- -- | `PGError` or a JavaScript exception in the Aff context). If you want to -- | `PGError` or a JavaScript exception in the Aff context). If you want to
-- -- | change the transaction mode, issue a separate `SET TRANSACTION` statement -- | change the transaction mode, issue a separate `SET TRANSACTION` statement
-- -- | within the transaction. -- | within the transaction.
-- withTransaction withTransaction
-- :: forall a :: forall a
-- . Connection . Connection
-- -> (Maybe PGError -> Aff a) -> Aff a
-- -> Aff a -> Aff (Either PGError a)
-- withTransaction conn action = withTransaction conn action =
-- begin *> lift (try $ runExceptT action) >>= case _ of begin >>= case _ of
-- Left jsErr -> do Nothing do
-- rollback a action `catchError` \jsErr do
-- lift $ throwError jsErr void $ rollback
-- Right (Left pgErr) -> do throwError jsErr
-- rollback commit >>= case _ of
-- throwError pgErr Just pgError pure (Left pgError)
-- Right (Right value) -> do Nothing pure (Right a)
-- commit Just pgError pure (Left pgError)
-- pure value where
-- begin = execute conn (Query "BEGIN TRANSACTION") Row0
-- where commit = execute conn (Query "COMMIT TRANSACTION") Row0
-- begin = execute conn (Query "BEGIN TRANSACTION") Row0 rollback = execute conn (Query "ROLLBACK TRANSACTION") Row0
-- commit = execute conn (Query "COMMIT TRANSACTION") Row0
-- rollback = execute conn (Query "ROLLBACK TRANSACTION") Row0
-- | Execute a PostgreSQL query and discard its results. -- | Execute a PostgreSQL query and discard its results.
execute execute

View File

@ -20,7 +20,7 @@ import Data.Maybe (Maybe(..), fromJust)
import Data.Newtype (unwrap) import Data.Newtype (unwrap)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Database.PostgreSQL (Connection, PG, PGError(..), PoolConfiguration, Query(Query), Row0(Row0), Row1(Row1), Row2(Row2), Row3(Row3), Row9(Row9), command, execute, newPool, onIntegrityError, query, scalar, withConnection, withTransaction) import Database.PostgreSQL.PG (Connection, PG, PGError(..), PoolConfiguration, Query(Query), Row0(Row0), Row1(Row1), Row2(Row2), Row3(Row3), Row9(Row9), command, execute, newPool, onIntegrityError, query, scalar, withConnection, withTransaction)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff, error, launchAff) import Effect.Aff (Aff, error, launchAff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)