refactor(sql): minor esqueleto refactoring
This commit is contained in:
parent
fb82dcbb33
commit
173468f246
@ -30,7 +30,7 @@ module Database.Esqueleto.Utils
|
|||||||
, maybe, maybe2, maybeEq, guardMaybe, unsafeCoalesce
|
, maybe, maybe2, maybeEq, guardMaybe, unsafeCoalesce
|
||||||
, bool
|
, bool
|
||||||
, max, min
|
, max, min
|
||||||
, greatest
|
, greatest, least
|
||||||
, abs
|
, abs
|
||||||
, SqlProject(..)
|
, SqlProject(..)
|
||||||
, (->.), (#>>.)
|
, (->.), (#>>.)
|
||||||
@ -114,8 +114,10 @@ infixl 4 ?=.
|
|||||||
isJust :: PersistField typ => E.SqlExpr (E.Value (Maybe typ)) -> E.SqlExpr (E.Value Bool)
|
isJust :: PersistField typ => E.SqlExpr (E.Value (Maybe typ)) -> E.SqlExpr (E.Value Bool)
|
||||||
isJust = E.not_ . E.isNothing
|
isJust = E.not_ . E.isNothing
|
||||||
|
|
||||||
|
-- | Deprecated, use coalesce directly
|
||||||
alt :: PersistField typ => E.SqlExpr (E.Value (Maybe typ)) -> E.SqlExpr (E.Value (Maybe typ)) -> E.SqlExpr (E.Value (Maybe typ))
|
alt :: PersistField typ => E.SqlExpr (E.Value (Maybe typ)) -> E.SqlExpr (E.Value (Maybe typ)) -> E.SqlExpr (E.Value (Maybe typ))
|
||||||
alt a b = E.case_ [(isJust a, a), (isJust b, b)] b
|
-- alt a b = E.case_ [(isJust a, a), (isJust b, b)] b
|
||||||
|
alt a b = E.coalesce [a,b]
|
||||||
|
|
||||||
infix 4 `isInfixOf`, `hasInfix`
|
infix 4 `isInfixOf`, `hasInfix`
|
||||||
|
|
||||||
@ -435,11 +437,12 @@ max, min :: PersistField a
|
|||||||
max a b = bool a b $ b E.>. a
|
max a b = bool a b $ b E.>. a
|
||||||
min a b = bool a b $ b E.<. a
|
min a b = bool a b $ b E.<. a
|
||||||
|
|
||||||
|
-- these alternatives for max/min ought to be more efficient
|
||||||
|
greatest :: PersistField a => E.SqlExpr (E.Value a) -> E.SqlExpr (E.Value a) -> E.SqlExpr (E.Value a)
|
||||||
|
greatest a b = E.unsafeSqlFunction "GREATEST" $ E.toArgList (a,b)
|
||||||
|
|
||||||
greatest :: PersistField a => (E.SqlExpr (E.Value a), E.SqlExpr (E.Value a)) -> E.SqlExpr (E.Value a)
|
least :: PersistField a => E.SqlExpr (E.Value a) -> E.SqlExpr (E.Value a) -> E.SqlExpr (E.Value a)
|
||||||
greatest = E.unsafeSqlFunction "GREATEST" . E.toArgList
|
least a b = E.unsafeSqlFunction "LEAST" $ E.toArgList (a,b)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
abs :: (PersistField a, Num a)
|
abs :: (PersistField a, Num a)
|
||||||
=> E.SqlExpr (E.Value a)
|
=> E.SqlExpr (E.Value a)
|
||||||
|
|||||||
Reference in New Issue
Block a user