diff --git a/cabal.project b/cabal.project index 9ea02062..128cf33b 100644 --- a/cabal.project +++ b/cabal.project @@ -1,3 +1,3 @@ -packages: . +packages: ., ../opaleye/*.cabal constraints: ansi-wl-pprint < 1.0.0 allow-newer: base16:base, base16:deepseq, base16:text diff --git a/rel8.cabal b/rel8.cabal index a5aa26c9..2934a96f 100644 --- a/rel8.cabal +++ b/rel8.cabal @@ -36,7 +36,7 @@ library , hasql >= 1.6.1.2 && < 1.9 , network-ip ^>= 0.3 , iproute ^>= 1.7 - , opaleye ^>= 0.10.2.1 + , opaleye ^>= 0.10.5.0 , pretty , profunctors , product-profunctors diff --git a/src/Rel8/Query/Limit.hs b/src/Rel8/Query/Limit.hs index 997eb955..fcdc9f4f 100644 --- a/src/Rel8/Query/Limit.hs +++ b/src/Rel8/Query/Limit.hs @@ -1,3 +1,5 @@ +{-# language LambdaCase #-} + module Rel8.Query.Limit ( limit , offset @@ -5,23 +7,33 @@ module Rel8.Query.Limit where -- base +import Data.Int (Int64) import Prelude -- opaleye import qualified Opaleye +import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye -- rel8 +import Rel8.Expr (Expr) +import Rel8.Expr.Opaleye (toColumn, toPrimExpr) import Rel8.Query ( Query ) import Rel8.Query.Opaleye ( mapOpaleye ) -- | @limit n@ select at most @n@ rows from a query. @limit n@ is equivalent -- to the SQL @LIMIT n@. -limit :: Word -> Query a -> Query a -limit = mapOpaleye . Opaleye.limit . fromIntegral +limit :: Expr Int64 -> Query a -> Query a +limit = mapOpaleye . Opaleye.limitField . toColumn . stripCast . toPrimExpr -- | @offset n@ drops the first @n@ rows from a query. @offset n@ is equivalent -- to the SQL @OFFSET n@. -offset :: Word -> Query a -> Query a -offset = mapOpaleye . Opaleye.offset . fromIntegral +offset :: Expr Int64 -> Query a -> Query a +offset = mapOpaleye . Opaleye.offsetField . toColumn . stripCast . toPrimExpr + + +stripCast :: Opaleye.PrimExpr -> Opaleye.PrimExpr +stripCast = \case + Opaleye.CastExpr "\"int8\"" a -> a + a -> a