Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 13 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,21 @@ jobs:
# interruption safety, MVars and STM, so we test the single threaded
# runtime, too.
# We also vary things like PGHOST to test both TCP and Unix Domain Sockets.
concurrently -g --timings --names pg18,pg17,pg16,pg15,pg14,single-threaded-rts,ghc984,ghc967 \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-tests.txt nix-build --no-out-link -A testsPg18' \
concurrently -g --timings --names pg18-ghc9122,pg17,pg16-ghc984-tcp,pg15-single-threaded-rts,pg14-ghc967 \
'nix-build --no-out-link --argstr ghc ghc9122 -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-ghc9122-tests.txt nix-build --no-out-link --argstr ghc ghc9122 -A testsPg18' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg17-tests.txt nix-build --no-out-link -A testsPg17' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg16-tests.txt nix-build --no-out-link -A testsPg16' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg15-tests.txt nix-build --no-out-link -A testsPg15' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg14-tests.txt nix-build --no-out-link -A testsPg14' \
'nix-build --no-out-link --argstr threading "-threaded" -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-single-threaded-rts-tests.txt nix-build --no-out-link --argstr threading "-threaded" -A testsPg18' \
'nix-build --no-out-link --argstr ghc ghc984 --argstr PGHOST localhost -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-ghc984-tests.txt nix-build --no-out-link --argstr ghc ghc984 -A testsPg18' \
'nix-build --no-out-link --argstr ghc ghc967 -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-ghc967-tests.txt nix-build --no-out-link --argstr ghc ghc967 -A testsPg18'
'nix-build --no-out-link --argstr ghc ghc984 --argstr PGHOST localhost -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg16-ghc984-tests.txt nix-build --no-out-link --argstr ghc ghc984 -A testsPg16' \
'nix-build --no-out-link --argstr threading "-threaded" -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg15-single-threaded-rts-tests.txt nix-build --no-out-link --argstr threading "-threaded" -A testsPg15' \
'nix-build --no-out-link --argstr ghc ghc967 -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg14-ghc967-tests.txt nix-build --no-out-link --argstr ghc ghc967 -A testsPg14'

- name: Run hpgsql-simple-compat tests
run: |
concurrently -g --timings --names pg18,pg17,pg16,pg15,pg14,ghc984,ghc967 \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-simple-compat-tests.txt nix-build --no-out-link -A hpgsqlSimpleCompatTestsPg18' \
concurrently -g --timings --names pg18-ghc9122,pg17,pg16-ghc984,pg15,pg14-ghc967 \
'nix-build --no-out-link --argstr ghc ghc984 -A hpgsql-simple-compat-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-ghc9122-simple-compat-tests.txt nix-build --no-out-link --argstr ghc ghc9122 -A hpgsqlSimpleCompatTestsPg18' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg17-simple-compat-tests.txt nix-build --no-out-link -A hpgsqlSimpleCompatTestsPg17' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg16-simple-compat-tests.txt nix-build --no-out-link -A hpgsqlSimpleCompatTestsPg16' \
'nix-build --no-out-link --argstr ghc ghc984 -A hpgsql-simple-compat-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg16-ghc984-simple-compat-tests.txt nix-build --no-out-link --argstr ghc ghc984 -A hpgsqlSimpleCompatTestsPg16' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg15-simple-compat-tests.txt nix-build --no-out-link -A hpgsqlSimpleCompatTestsPg15' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg14-simple-compat-tests.txt nix-build --no-out-link -A hpgsqlSimpleCompatTestsPg14' \
'nix-build --no-out-link --argstr ghc ghc984 -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-ghc984-simple-compat-tests.txt nix-build --no-out-link --argstr ghc ghc984 -A hpgsqlSimpleCompatTestsPg18' \
'nix-build --no-out-link --argstr ghc ghc967 -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-ghc967-simple-compat-tests.txt nix-build --no-out-link --argstr ghc ghc967 -A hpgsqlSimpleCompatTestsPg18'
'nix-build --no-out-link --argstr ghc ghc967 -A hpgsql-simple-compat-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg14-ghc967-simple-compat-tests.txt nix-build --no-out-link --argstr ghc ghc967 -A hpgsqlSimpleCompatTestsPg14'

build-aarch64-darwin:
runs-on: macos-14
Expand Down Expand Up @@ -103,21 +98,11 @@ jobs:
run: |
# We don't run these concurrently because Nix does not have a sandbox in Macs, so it's
# not worth the risk.
timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-tests.txt nix-build --no-out-link -A testsPg18
nix-build --no-out-link --argstr ghc ghc9122 -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-ghc9122-tests.txt nix-build --no-out-link --argstr ghc ghc9122 -A testsPg18
timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg17-tests.txt nix-build --no-out-link -A testsPg17
timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg16-tests.txt nix-build --no-out-link -A testsPg16
timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg15-tests.txt nix-build --no-out-link -A testsPg15
timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg14-tests.txt nix-build --no-out-link -A testsPg14

- name: Run tests with different combinations
run: |
# GHC's single and multi-threaded runtimes are different with respect
# to many things, and our library relies on a lot of ThreadId tracking,
# interruption safety, MVars and STM, so we test the single threaded
# runtime, too.
# We also vary things like PGHOST to test both TCP and Unix Domain Sockets.
nix-build --no-out-link --argstr threading "-threaded" -A hpgsql-tests
timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-single-threaded-rts-tests.txt nix-build --no-out-link --argstr threading "-threaded" --argstr PGHOST localhost -A testsPg18
nix-build --no-out-link --argstr ghc ghc984 --argstr PGHOST localhost -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg16-ghc984-tests.txt nix-build --no-out-link --argstr ghc ghc984 -A testsPg16
nix-build --no-out-link --argstr threading "-threaded" -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg15-single-threaded-rts-tests.txt nix-build --no-out-link --argstr threading "-threaded" -A testsPg15
nix-build --no-out-link --argstr ghc ghc967 -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg14-ghc967-tests.txt nix-build --no-out-link --argstr ghc ghc967 -A testsPg14

- name: Run hpgsql-simple-compat tests
run: |
Expand Down
4 changes: 2 additions & 2 deletions INTERRUPTION-SAFETY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ withTransaction $
With Hpgsql you shouldn't run into such issues, or at least we promise that:
- Hpgsql is interruption-safe, so a query can be interrupted by asynchronous exceptions and you should still be able to run new queries on the same connection without any other side-effects. Naturally, it is up to you to determine which queries ran or not to completion, since they might have side-effects*.
- Hpgsql will throw either `PostgresError` or `IrrecoverableHpgsqlError`, and:
- If you receive a `IrrecoverableHpgsqlError`, Hpgsql makes no promises about which statements ran to completion and what connection state is, and you should `closeForcefully` the connection without running any other queries. These errors should only be thrown for "obvious" developer mistakes from which usually there would be no way to proceed, anyway.
- If you receive a `IrrecoverableHpgsqlError`, Hpgsql makes no promises about which statements ran to completion and what the connection state is. You should `closeForcefully` the connection without running any other queries. These errors should only be thrown for "obvious" developer mistakes from which usually there would be no way to proceed, anyway.
- If you receive a `PostgresError` exception, postgres and Hpgsql's states are synced and you can issue new queries afterwards.
- It is possible Hpgsql throws a different kind of exception. File a bug report if that happens, and if you know it came from Hpgsql, treat it like a `IrrecoverableHpgsqlError`.
- You can file a bug report if Hpgsql throws a different kind of exception, and we'll treat it like a bug.

* There are edge cases with different behaviour, but hpgsql will document them or throw an `IrrecoverableHpgsqlError` with informative instructions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ f val = do

## Current status

Hpgsql is in active development, is new and has not been used in Production yet. It currently lacks (at least) many of the authentication methods that libpq provides; for now only cleartext and MD5 password auth are supported, and only unencrypted connections.
Hpgsql is in active development, is new and has not been used in Production yet. It currently lacks many of the authentication methods that libpq provides; for now only cleartext, MD5 and SCRAM-SHA-256 password auth are supported, and only unencrypted connections.

That being said, one of my other projects, codd, [has a tests-passing branch using hpgsql-simple-compat](https://github.com/mzabani/codd/pull/227) (the nearly API compatible fork of postgresql-simple described in the next section) with very few modifications.

Expand Down
24 changes: 13 additions & 11 deletions Runfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ ci-tests:

hlint .

concurrently -g --timings --names pg18,pg17,pg16,pg15,pg14 \
'nix-build --no-out-link -A testsPg18' \
'nix-build --no-out-link -A testsPg17' \
'nix-build --no-out-link -A testsPg16' \
'nix-build --no-out-link -A testsPg15' \
'nix-build --no-out-link -A testsPg14'

# concurrently -g --timings --names single-threaded,ghc984,ghc967 \
# 'nix-build --no-out-link --argstr threading "-threaded" -A testsPg18' \
# 'nix-build --no-out-link --argstr ghc ghc984 -A testsPg18' \
# 'nix-build --no-out-link --argstr ghc ghc967 -A testsPg18'
concurrently -g --timings --names pg18-ghc9122,pg17,pg16-ghc984-tcp,pg15-single-threaded-rts,pg14-ghc967 \
'nix-build --no-out-link --argstr ghc ghc9122 -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-ghc9122-tests.txt nix-build --no-out-link --argstr ghc ghc9122 -A testsPg18' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg17-tests.txt nix-build --no-out-link -A testsPg17' \
'nix-build --no-out-link --argstr ghc ghc984 --argstr PGHOST localhost -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg16-ghc984-tests.txt nix-build --no-out-link --argstr ghc ghc984 -A testsPg16' \
'nix-build --no-out-link --argstr threading "-threaded" -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg15-single-threaded-rts-tests.txt nix-build --no-out-link --argstr threading "-threaded" -A testsPg15' \
'nix-build --no-out-link --argstr ghc ghc967 -A hpgsql-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg14-ghc967-tests.txt nix-build --no-out-link --argstr ghc ghc967 -A testsPg14'

concurrently -g --timings --names pg18-ghc9122,pg17,pg16-ghc984,pg15,pg14-ghc967 \
'nix-build --no-out-link --argstr ghc ghc984 -A hpgsql-simple-compat-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg18-ghc9122-simple-compat-tests.txt nix-build --no-out-link --argstr ghc ghc9122 -A hpgsqlSimpleCompatTestsPg18' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg17-simple-compat-tests.txt nix-build --no-out-link -A hpgsqlSimpleCompatTestsPg17' \
'nix-build --no-out-link --argstr ghc ghc984 -A hpgsql-simple-compat-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg16-ghc984-simple-compat-tests.txt nix-build --no-out-link --argstr ghc ghc984 -A hpgsqlSimpleCompatTestsPg16' \
'timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg15-simple-compat-tests.txt nix-build --no-out-link -A hpgsqlSimpleCompatTestsPg15' \
'nix-build --no-out-link --argstr ghc ghc967 -A hpgsql-simple-compat-tests && timeout 5m scripts/ci/run-tests-and-annotate-with-error.sh local/pg14-ghc967-simple-compat-tests.txt nix-build --no-out-link --argstr ghc ghc967 -A hpgsqlSimpleCompatTestsPg14'


##
Expand Down
12 changes: 7 additions & 5 deletions hpgsql-simple-compat/hpgsql-simple-compat.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ category: Database
homepage: https://github.com/mzabani/hpgsql#readme
bug-reports: https://github.com/mzabani/hpgsql/issues
build-type: Simple
tested-with:
GHC ==9.6.7
|| ==9.8.4
|| ==9.10.3
|| ==9.12.2

source-repository head
type: git
Expand Down Expand Up @@ -84,21 +89,18 @@ library

-- GHC bundled libs
build-depends:
base >= 4.18 && < 4.21
base >= 4.18 && < 4.22
, bytestring >= 0.11 && < 0.13
, case-insensitive >= 1.2 && < 1.3
, containers >= 0.6 && < 0.8
, template-haskell >= 2.20 && < 2.23
, template-haskell >= 2.20 && < 2.24
, text >= 2.0 && < 2.2
, aeson >= 2.2 && < 2.3
, attoparsec >= 0.14 && < 0.15
, haskell-src-meta >= 0.8 && < 0.9
, hpgsql >= 0.2 && < 0.3
, hashable >= 1.5 && < 1.6
, mtl >= 2.3 && < 2.4
, streaming >= 0.2 && < 0.3
, time-compat >= 1.9 && < 1.10
, transformers >= 0.6 && < 0.7
, Only >= 0.1 && < 0.2
, scientific >= 0.3 && < 0.4
, uuid-types >= 1.0 && < 1.1
Expand Down
3 changes: 1 addition & 2 deletions hpgsql-simple-compat/src/Database/PostgreSQL/Simple/Copy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import qualified Data.ByteString.Char8 as B
import Data.Int (Int64)
import qualified Data.Text as Text
import Data.Text.Encoding (decodeUtf8)
import Data.Typeable (Typeable)
import Database.PostgreSQL.Simple.HpgsqlUtils (toHpgsqlQuery)
import Database.PostgreSQL.Simple.Internal
import Database.PostgreSQL.Simple.ToRow (ToRow)
Expand Down Expand Up @@ -80,7 +79,7 @@ data CopyOutResult
| -- | No more rows, and a count of the
-- number of rows returned.
CopyOutDone {-# UNPACK #-} !Int64
deriving (Eq, Typeable, Show)
deriving (Eq, Show)

-- | Feed some data to a @COPY FROM STDIN@ query. Note that
-- the data does not need to represent a single row, or even an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ module Database.PostgreSQL.Simple.Errors
where

import Control.Exception as E

import Data.Attoparsec.ByteString.Char8
import Data.ByteString (ByteString)
import Data.Typeable

import Database.PostgreSQL.Simple.Internal

-- Examples of parsed error messages
Expand All @@ -55,7 +52,7 @@ data ConstraintViolation
CheckViolation ByteString ByteString
| -- | Name of the exclusion violation constraint
ExclusionViolation ByteString
deriving (Show, Eq, Ord, Typeable)
deriving (Show, Eq, Ord)

-- Default instance should be enough
instance Exception ConstraintViolation where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ data ResultError
errHaskellType :: String,
errMessage :: String
}
deriving (Eq, Show, Typeable)
deriving (Eq, Show)

instance Exception ResultError where
toException = postgresqlExceptionToException
Expand All @@ -176,8 +176,8 @@ class FromField a where
fromField =
let dec = Hpgsql.fieldDecoder
in \f ->
if (Hpgsql.allowedPgTypes dec) f
then \mbs -> Conversion $ \_encCtx -> case (Hpgsql.fieldValueDecoder dec) f mbs of
if Hpgsql.allowedPgTypes dec f
then \mbs -> Conversion $ \_encCtx -> case Hpgsql.fieldValueDecoder dec f mbs of
Right v -> Ok v
Left err -> Errors [toException $ userError err]
else \_ -> Conversion $ \_encCtx -> Errors [toException $ userError "Invalid type OID for FromField instance"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import qualified Data.Text as TS
import qualified Data.Text.Encoding as TS
import Data.Text.Encoding.Error (UnicodeException)
import qualified Data.Text.Lazy as TL
import Data.Typeable

class ToHStore a where
toHStore :: a -> HStoreBuilder
Expand All @@ -36,7 +35,6 @@ class ToHStore a where
data HStoreBuilder
= Empty
| Comma !Builder
deriving (Typeable)

instance ToHStore HStoreBuilder where
toHStore = id
Expand Down Expand Up @@ -68,7 +66,6 @@ class ToHStoreText a where

-- | Represents escape text, ready to be the key or value to a hstore value
newtype HStoreText = HStoreText Builder
deriving stock (Typeable)
deriving newtype (Semigroup, Monoid)

instance ToHStoreText HStoreText where
Expand Down Expand Up @@ -112,13 +109,13 @@ hstore (toHStoreText -> (HStoreText key)) (toHStoreText -> (HStoreText val)) =
`mappend` char8 '"'
)

newtype HStoreList = HStoreList {fromHStoreList :: [(Text, Text)]} deriving (Typeable, Show)
newtype HStoreList = HStoreList {fromHStoreList :: [(Text, Text)]} deriving (Show)

-- | hstore
instance ToHStore HStoreList where
toHStore (HStoreList xs) = mconcat (map (uncurry hstore) xs)

newtype HStoreMap = HStoreMap {fromHStoreMap :: Map Text Text} deriving (Eq, Ord, Typeable, Show)
newtype HStoreMap = HStoreMap {fromHStoreMap :: Map Text Text} deriving (Eq, Ord, Show)

instance ToHStore HStoreMap where
toHStore (HStoreMap xs) = Map.foldrWithKey f mempty xs
Expand Down
12 changes: 5 additions & 7 deletions hpgsql-simple-compat/src/Database/PostgreSQL/Simple/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ data Connection = Connection
connectionTempNameCounter :: {-# UNPACK #-} !(IORef Int64),
hpgConn :: HPgConnection
}
deriving (Typeable)

instance Eq Connection where
x == y = hpgConn x == hpgConn y

-- | Superclass for postgresql exceptions
data SomePostgreSqlException = forall e. (Exception e) => SomePostgreSqlException e
deriving (Typeable)

postgresqlExceptionToException :: (Exception e) => e -> SomeException
postgresqlExceptionToException = toException . SomePostgreSqlException
Expand All @@ -83,7 +81,7 @@ data SqlError = SqlError
-- to help debugging the source of errors.
sqlStatement :: ByteString
}
deriving (Eq, Show, Typeable)
deriving (Eq, Show)

fatalError :: ByteString -> SqlError
fatalError msg = SqlError "" FatalError msg "" "" ""
Expand All @@ -98,7 +96,7 @@ data QueryError = QueryError
{ qeMessage :: String,
qeQuery :: Query
}
deriving (Eq, Show, Typeable)
deriving (Eq, Show)

instance Exception QueryError where
toException = postgresqlExceptionToException
Expand All @@ -112,7 +110,7 @@ data FormatError = FormatError
fmtQuery :: Query,
fmtParams :: [ByteString]
}
deriving (Eq, Show, Typeable)
deriving (Eq, Show)

instance Exception FormatError where
toException = postgresqlExceptionToException
Expand All @@ -125,7 +123,7 @@ data ConnectInfo = ConnectInfo
connectPassword :: String,
connectDatabase :: String
}
deriving (Generic, Eq, Read, Show, Typeable)
deriving (Generic, Eq, Read, Show)

-- | Default information for setting up a connection.
--
Expand Down Expand Up @@ -240,7 +238,7 @@ withConnection Connection {..} m = m $ PQ.Connection hpgConn
-- for detailed information regarding libpq and SSL.
connectPostgreSQL :: ByteString -> IO Connection
connectPostgreSQL connstr = do
connectionObjects <- newMVar (IntMap.empty)
connectionObjects <- newMVar IntMap.empty
connectionTempNameCounter <- newIORef 0
case Hpgsql.Connection.parseLibpqConnectionString (TE.decodeUtf8 connstr) of
Left err -> error err
Expand Down
Loading