Minor refactor
This commit is contained in:
parent
bf083c9854
commit
3bb5b6c7fb
@ -7,7 +7,6 @@ module Database.Esqueleto.Utils
|
||||
, SqlIn(..)
|
||||
, mkExactFilter, mkContainsFilter
|
||||
, anyFilter
|
||||
, inList
|
||||
) where
|
||||
|
||||
import ClassyPrelude.Yesod hiding (isInfixOf, any, all)
|
||||
@ -100,12 +99,4 @@ anyFilter :: (Foldable f) => f (t -> Set.Set Text-> E.SqlExpr (E.Value Bool))
|
||||
-> t -> Set.Set Text-> E.SqlExpr (E.Value Bool)
|
||||
anyFilter fltrs needle criterias = F.foldr aux false fltrs
|
||||
where
|
||||
aux fltr acc = fltr needle criterias E.||. acc
|
||||
|
||||
-- | Convenience for Sorting by a Column being element of a certain List
|
||||
-- Does not work, may produce esqueleto error
|
||||
-- `unsafeSqlBinOp: non-id/composite keys not expected here` somehow
|
||||
inList :: (PersistField typ, PersistEntity val)
|
||||
=> EntityField val typ -> [typ] -> E.SqlExpr (Entity val) -> E.SqlExpr (E.Value Bool)
|
||||
inList _column [] = const $ E.val True
|
||||
inList column l = \row -> row E.^. column `E.in_` E.valList l
|
||||
aux fltr acc = fltr needle criterias E.||. acc
|
||||
@ -404,8 +404,9 @@ postAdminFeaturesR = do
|
||||
]
|
||||
dbtSorting = Map.fromList
|
||||
[ ("key" , SortColumn (E.^. StudyTermsKey))
|
||||
, ("isnew" , SortColumn (StudyTermsKey `E.inList` (unStudyTermsKey <$> Set.toList newKeys)))
|
||||
, ("isbad" , SortColumn (StudyTermsKey `E.inList` (unStudyTermsKey <$> Set.toList badKeys)))
|
||||
, ("isnew" , SortColumn (\studyTerm -> studyTerm E.^. StudyTermsKey `E.in_` E.valList (unStudyTermsKey <$> Set.toList newKeys)))
|
||||
-- Remember: sorting with E.in_ by StudyTermsId instead will produce esqueleto-error "unsafeSqlBinOp: non-id/composite keys not expected here"
|
||||
, ("isbad" , SortColumn (\studyTerm -> studyTerm E.^. StudyTermsKey `E.in_` E.valList (unStudyTermsKey <$> Set.toList badKeys)))
|
||||
, ("name" , SortColumn (E.^. StudyTermsName))
|
||||
, ("short" , SortColumn (E.^. StudyTermsShorthand))
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user