Use persistent 1.3+ new limit/offset func (closes #35).
This code was actually written by @gbwey and it's being manually merged with some changes by me.
This commit is contained in:
parent
030423da54
commit
0de8242634
@ -65,7 +65,7 @@ library
|
|||||||
build-depends:
|
build-depends:
|
||||||
base >= 4.5 && < 4.8
|
base >= 4.5 && < 4.8
|
||||||
, text >= 0.11
|
, text >= 0.11
|
||||||
, persistent >= 1.2 && < 1.4
|
, persistent >= 1.3 && < 1.4
|
||||||
, transformers >= 0.2
|
, transformers >= 0.2
|
||||||
, unordered-containers >= 0.2
|
, unordered-containers >= 0.2
|
||||||
, tagged >= 0.2
|
, tagged >= 0.2
|
||||||
|
|||||||
@ -65,7 +65,6 @@ import qualified Data.HashSet as HS
|
|||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Lazy as TL
|
import qualified Data.Text.Lazy as TL
|
||||||
import qualified Data.Text.Lazy.Builder as TLB
|
import qualified Data.Text.Lazy.Builder as TLB
|
||||||
import qualified Data.Text.Lazy.Builder.Int as TLBI
|
|
||||||
|
|
||||||
import Database.Esqueleto.Internal.Language
|
import Database.Esqueleto.Internal.Language
|
||||||
|
|
||||||
@ -782,7 +781,7 @@ toRawSql mode (conn, firstIdentState) query =
|
|||||||
, makeGroupBy info groupByClause
|
, makeGroupBy info groupByClause
|
||||||
, makeHaving info havingClause
|
, makeHaving info havingClause
|
||||||
, makeOrderBy info orderByClauses
|
, makeOrderBy info orderByClauses
|
||||||
, makeLimit info limitClause
|
, makeLimit info limitClause orderByClauses
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -894,22 +893,12 @@ makeOrderBy info os = first ("\nORDER BY " <>) $ uncommas' (map mk os)
|
|||||||
orderByType DESC = " DESC"
|
orderByType DESC = " DESC"
|
||||||
|
|
||||||
|
|
||||||
makeLimit :: IdentInfo -> LimitClause -> (TLB.Builder, [PersistValue])
|
makeLimit :: IdentInfo -> LimitClause -> [OrderByClause] -> (TLB.Builder, [PersistValue])
|
||||||
makeLimit _ (Limit Nothing Nothing) = mempty
|
makeLimit (conn,_) (Limit ml mo) orderByClauses =
|
||||||
makeLimit _ (Limit Nothing (Just 0)) = mempty
|
let limitRaw = connLimitOffset conn (v ml, v mo) hasOrderClause "\n"
|
||||||
makeLimit info (Limit ml mo) = (ret, mempty)
|
hasOrderClause = not (null orderByClauses)
|
||||||
where
|
v = maybe 0 fromIntegral
|
||||||
ret = TLB.singleton '\n' <> (limitTLB <> offsetTLB)
|
in (TLB.fromText limitRaw, mempty)
|
||||||
|
|
||||||
limitTLB =
|
|
||||||
case ml of
|
|
||||||
Just l -> "LIMIT " <> TLBI.decimal l
|
|
||||||
Nothing -> TLB.fromText (connNoLimit $ fst info)
|
|
||||||
|
|
||||||
offsetTLB =
|
|
||||||
case mo of
|
|
||||||
Just o -> " OFFSET " <> TLBI.decimal o
|
|
||||||
Nothing -> mempty
|
|
||||||
|
|
||||||
|
|
||||||
parens :: TLB.Builder -> TLB.Builder
|
parens :: TLB.Builder -> TLB.Builder
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user