Skip to content
Open
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
11 changes: 9 additions & 2 deletions beam-core/Database/Beam/Backend/SQL/Row.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE LambdaCase #-} -- for LambdaCase

module Database.Beam.Backend.SQL.Row
( FromBackendRowF(..), FromBackendRowM(..)
Expand Down Expand Up @@ -63,7 +64,11 @@ data FromBackendRowF be f where
ParseOneField :: (BackendFromField be a, Typeable a) => (a -> f) -> FromBackendRowF be f
Alt :: FromBackendRowM be a -> FromBackendRowM be a -> (a -> f) -> FromBackendRowF be f
FailParseWith :: BeamRowReadError -> FromBackendRowF be f
deriving instance Functor (FromBackendRowF be)
instance Functor (FromBackendRowF be) where
fmap f = \case
ParseOneField p -> ParseOneField $ f . p
Alt a b p -> Alt a b $ f . p
FailParseWith e -> FailParseWith e
newtype FromBackendRowM be a = FromBackendRowM (F (FromBackendRowF be) a)
deriving (Functor, Applicative)

Expand Down Expand Up @@ -202,7 +207,9 @@ instance (FromBackendRow be x, FromBackendRow be SqlNull) => FromBackendRow be (
pure ()))
valuesNeeded be _ = valuesNeeded be (Proxy @x)

deriving instance Generic (a, b, c, d, e, f, g, h)
#if !MIN_VERSION_base(4,16,0)
deriving instance Generic (a, b, c, d, e, f, g, h)
#endif

instance (BeamBackend be, FromBackendRow be t) => FromBackendRow be (Tagged tag t) where
fromBackendRow = Tagged <$> fromBackendRow
Expand Down
2 changes: 1 addition & 1 deletion beam-core/Database/Beam/Query/Combinators.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeFamilyDependencies #-}

module Database.Beam.Query.Combinators
( -- * Various SQL functions and constructs
Expand Down
2 changes: 2 additions & 0 deletions beam-migrate/Database/Beam/Haskell/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,5 +1033,7 @@ instance Hashable (Hs.CName ())
instance Hashable (Hs.DerivStrategy ())
instance Hashable (Hs.MaybePromotedName ())
#endif
#if !MIN_VERSION_hashable(1, 3, 4)
instance Hashable a => Hashable (S.Set a) where
hashWithSalt s a = hashWithSalt s (S.toList a)
#endif
14 changes: 3 additions & 11 deletions beam-migrate/Database/Beam/Migrate/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,12 @@ createTableActionProvider =
guard (preTblNm == postTblNm)

(columnsP, columns) <- pure . unzip $
do columnP@
(TableHasColumn tblNm colNm schema :: TableHasColumn be) <-
findPostConditions
do columnP@(TableHasColumn tblNm colNm schema :: TableHasColumn be) <- findPostConditions
guard (tblNm == postTblNm && dataTypeHasBeenCreated schema findPreConditions)

(constraintsP, constraints) <-
pure . unzip $ do
constraintP@
(TableColumnHasConstraint tblNm' colNm' c
:: TableColumnHasConstraint be) <-
findPostConditions
constraintP@(TableColumnHasConstraint tblNm' colNm' c :: TableColumnHasConstraint be) <- findPostConditions
guard (postTblNm == tblNm')
guard (colNm == colNm')

Expand Down Expand Up @@ -379,10 +374,7 @@ addColumnProvider =

(constraintsP, constraints) <-
pure . unzip $ do
constraintP@
(TableColumnHasConstraint tblNm'' colNm' c
:: TableColumnHasConstraint be) <-
findPostConditions
constraintP@(TableColumnHasConstraint tblNm'' colNm' c :: TableColumnHasConstraint be) <- findPostConditions
guard (tblNm == tblNm'')
guard (colNm == colNm')

Expand Down
10 changes: 9 additions & 1 deletion beam-migrate/Database/Beam/Migrate/Serialization.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import Control.Applicative
import Control.Monad

import Data.Aeson
#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.Key as DAK
#endif
import Data.Aeson.Types (Parser)
import qualified Data.Dependent.Map as D
import qualified Data.GADT.Compare as D
Expand Down Expand Up @@ -321,8 +324,13 @@ sql92Deserializers = mconcat
, beamDeserializer deserializeSql92ReferentialAction
, beamDeserializer deserializeSql92Attributes ]
where
#if MIN_VERSION_aeson(2,0,0)
makeKey = DAK.fromText
#else
makeKey = id
#endif
parseSub nm o key parse =
withObject (unpack (nm <> "." <> key)) parse =<< o .: key
withObject (unpack (nm <> "." <> key)) parse =<< o .: makeKey key

deserializeSql92DataType :: BeamDeserializers be' -> Value
-> Parser (BeamSqlBackendDataTypeSyntax be)
Expand Down
7 changes: 6 additions & 1 deletion beam-postgres/Database/Beam/Postgres/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,12 @@ data PgF next where
FromBackendRow Postgres x =>
(Maybe x -> next) -> PgF next
PgLiftWithHandle :: (Pg.Connection -> IO a) -> (a -> next) -> PgF next
deriving instance Functor PgF
instance Functor PgF where
fmap f = \case
PgLiftIO io n -> PgLiftIO io $ f . n
PgRunReturning cmd consume n -> PgRunReturning cmd consume $ f . n
PgFetchNext n -> PgFetchNext $ f . n
PgLiftWithHandle withConn n -> PgLiftWithHandle withConn $ f . n

-- | 'MonadBeam' in which we can run Postgres commands. See the documentation
-- for 'MonadBeam' on examples of how to use.
Expand Down
6 changes: 3 additions & 3 deletions beam-postgres/Database/Beam/Postgres/PgSpecific.hs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ arrayOf_ q =
data PgBoundType
= Inclusive
| Exclusive
deriving (Show, Generic)
deriving (Eq, Show, Generic)
instance Hashable PgBoundType

lBound :: PgBoundType -> ByteString
Expand All @@ -452,7 +452,7 @@ uBound Exclusive = ")"

-- | Represents a single bound on a Range. A bound always has a type, but may not have a value
-- (the absense of a value represents unbounded).
data PgRangeBound a = PgRangeBound PgBoundType (Maybe a) deriving (Show, Generic)
data PgRangeBound a = PgRangeBound PgBoundType (Maybe a) deriving (Eq, Show, Generic)

inclusive :: a -> PgRangeBound a
inclusive = PgRangeBound Inclusive . Just
Expand All @@ -471,7 +471,7 @@ unbounded = PgRangeBound Exclusive Nothing
data PgRange (n :: *) a
= PgEmptyRange
| PgRange (PgRangeBound a) (PgRangeBound a)
deriving (Show, Generic)
deriving (Eq, Show, Generic)

instance Hashable a => Hashable (PgRangeBound a)

Expand Down
2 changes: 2 additions & 0 deletions beam-sqlite/Database/Beam/Sqlite/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import GHC.Generics
-- value list is ignored.
data SqliteSyntax = SqliteSyntax ((SQLData -> Builder) -> Builder) (DL.DList SQLData)
newtype SqliteData = SqliteData SQLData -- newtype for Hashable
deriving (Eq)

instance Show SqliteSyntax where
show (SqliteSyntax s d) =
Expand All @@ -118,6 +119,7 @@ instance Hashable SqliteSyntax where
hashWithSalt salt (SqliteSyntax s d) =
hashWithSalt salt ( toLazyByteString (withPlaceholders s)
, map SqliteData (DL.toList d) )

instance Hashable SqliteData where
hashWithSalt salt (SqliteData (SQLInteger i)) = hashWithSalt salt (0 :: Int, i)
hashWithSalt salt (SqliteData (SQLFloat d)) = hashWithSalt salt (1 :: Int, d)
Expand Down