Skip to content

Commit

Permalink
Modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-volkov committed Dec 25, 2023
1 parent d4bcbb5 commit 67ae6eb
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 86 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Compile, test and check the docs

on:
workflow_call:

jobs:

check:

strategy:
fail-fast: false
matrix:
include:
- ghc: 8.8.1
ghc-options: ""
ignore-haddock: true
ignore-cabal-check: true
- ghc: latest
ignore-cabal-check: true

runs-on: ubuntu-latest

services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:

- uses: nikita-volkov/build-and-test-cabal-package.github-action@v1
with:
ghc: ${{matrix.ghc}}
ghc-options: ${{matrix.ghc-options}}
ignore-haddock: ${{matrix.ignore-haddock}}
ignore-cabal-check: ${{matrix.ignore-cabal-check}}
17 changes: 17 additions & 0 deletions .github/workflows/on-push-to-master-or-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Compile, test and check the docs

on:
push:
branches:
- master
pull_request:

jobs:

format:
uses: nikita-volkov/haskell-hackage-lib-github-actions-workflows/.github/workflows/format.yaml@v2
secrets: inherit

check:
uses: ./.github/workflows/check.yaml
secrets: inherit
32 changes: 32 additions & 0 deletions .github/workflows/on-push-to-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release the lib to Hackage

on:
push:
branches:
- supermajor
- major
- minor
- patch

concurrency:
group: release
cancel-in-progress: false

jobs:

format:
uses: nikita-volkov/haskell-hackage-lib-github-actions-workflows/.github/workflows/format.yaml@v2
secrets: inherit

check:
uses: ./.github/workflows/check.yaml
secrets: inherit

release:
needs:
- format
- check
uses: nikita-volkov/haskell-hackage-lib-github-actions-workflows/.github/workflows/release.yaml@v2
secrets: inherit
with:
prefix-tag-with-v: false
61 changes: 0 additions & 61 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
9 changes: 6 additions & 3 deletions conflicts-test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import qualified Main.Statements as D
import qualified Main.Transactions as E
import Prelude

main :: IO ()
main =
bracket acquire release use
where
acquire =
(,) <$> acquire <*> acquire
where
acquire =
join $
fmap (either (fail . show) return) $
A.acquire connectionSettings
join
$ fmap (either (fail . show) return)
$ A.acquire connectionSettings
where
connectionSettings =
A.settings "localhost" 5432 "postgres" "" "postgres"
Expand All @@ -41,10 +42,12 @@ main =
tests =
[readAndWriteTransactionsTest, transactionsTest, transactionAndQueryTest]

session :: A.Connection -> B.Session a -> IO a
session connection session =
B.run session connection
>>= either (fail . show) return

transaction :: A.Connection -> C.Transaction a -> IO a
transaction connection transaction =
session connection (G.transaction G.RepeatableRead G.Write transaction)

Expand Down
1 change: 0 additions & 1 deletion library/Hasql/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ module Hasql.Transaction
)
where

import Hasql.Transaction.Config
import Hasql.Transaction.Private.Transaction
6 changes: 2 additions & 4 deletions library/Hasql/Transaction/Private/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Data.Either as Exports
import Data.Fixed as Exports
import Data.Foldable as Exports hiding (toList)
import Data.Function as Exports hiding (id, (.))
import Data.Functor as Exports
import Data.Functor as Exports hiding (unzip)
import Data.Functor.Contravariant as Exports
import Data.Functor.Contravariant.Divisible as Exports
import Data.Functor.Identity as Exports
Expand Down Expand Up @@ -71,13 +71,11 @@ import System.IO.Unsafe as Exports
import System.Mem as Exports
import System.Mem.StableName as Exports
import System.Timeout as Exports
import Text.ParserCombinators.ReadP as Exports (ReadP, ReadS, readP_to_S, readS_to_P)
import Text.ParserCombinators.ReadPrec as Exports (ReadPrec, readP_to_Prec, readPrec_to_P, readPrec_to_S, readS_to_Prec)
import Text.Printf as Exports (hPrintf, printf)
import Text.Read as Exports (Read (..), readEither, readMaybe)
import Unsafe.Coerce as Exports
import Prelude as Exports hiding (all, and, any, concat, concatMap, elem, fail, foldl, foldl1, foldr, foldr1, id, mapM, mapM_, maximum, minimum, notElem, or, product, sequence, sequence_, sum, (.))

tryError :: MonadError e m => m a -> m (Either e a)
tryError :: (MonadError e m) => m a -> m (Either e a)
tryError m =
catchError (liftM Right m) (return . Left)
2 changes: 2 additions & 0 deletions library/Hasql/Transaction/Private/Sessions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ tryTransaction level mode body preparable = do
handleTransactionError error $ return Nothing
Nothing -> return Nothing

commitOrAbort :: Bool -> Bool -> Session ()
commitOrAbort commit preparable =
if commit
then statement () (Statements.commitTransaction preparable)
else statement () (Statements.abortTransaction preparable)

handleTransactionError :: QueryError -> Session a -> Session a
handleTransactionError error onTransactionError = case error of
QueryError _ _ (ResultError (ServerError "40001" _ _ _ _)) -> onTransactionError
error -> throwError error
6 changes: 2 additions & 4 deletions library/Hasql/Transaction/Private/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import qualified Hasql.Statement as A
import Hasql.Transaction.Config
import Hasql.Transaction.Private.Prelude
import qualified Hasql.Transaction.Private.Sessions as D
import qualified Hasql.Transaction.Private.Statements as C

-- |
-- A composable abstraction over the retryable transactions.
Expand All @@ -17,12 +16,11 @@ newtype Transaction a
= Transaction (StateT Bool B.Session a)
deriving (Functor, Applicative, Monad)

instance Semigroup a => Semigroup (Transaction a) where
instance (Semigroup a) => Semigroup (Transaction a) where
(<>) = liftA2 (<>)

instance Monoid a => Monoid (Transaction a) where
instance (Monoid a) => Monoid (Transaction a) where
mempty = pure mempty
mappend = liftA2 mappend

-- |
-- Execute the transaction using the provided isolation level and mode.
Expand Down
1 change: 0 additions & 1 deletion stack.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions stack.yaml.lock

This file was deleted.

0 comments on commit 67ae6eb

Please sign in to comment.