Minor refactor
This commit is contained in:
parent
bf083c9854
commit
3bb5b6c7fb
@ -7,7 +7,6 @@ module Database.Esqueleto.Utils
|
|||||||
, SqlIn(..)
|
, SqlIn(..)
|
||||||
, mkExactFilter, mkContainsFilter
|
, mkExactFilter, mkContainsFilter
|
||||||
, anyFilter
|
, anyFilter
|
||||||
, inList
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import ClassyPrelude.Yesod hiding (isInfixOf, any, all)
|
import ClassyPrelude.Yesod hiding (isInfixOf, any, all)
|
||||||
@ -101,11 +100,3 @@ anyFilter :: (Foldable f) => f (t -> Set.Set Text-> E.SqlExpr (E.Value Bool))
|
|||||||
anyFilter fltrs needle criterias = F.foldr aux false fltrs
|
anyFilter fltrs needle criterias = F.foldr aux false fltrs
|
||||||
where
|
where
|
||||||
aux fltr acc = fltr needle criterias E.||. acc
|
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
|
|
||||||
|
|||||||
@ -404,8 +404,9 @@ postAdminFeaturesR = do
|
|||||||
]
|
]
|
||||||
dbtSorting = Map.fromList
|
dbtSorting = Map.fromList
|
||||||
[ ("key" , SortColumn (E.^. StudyTermsKey))
|
[ ("key" , SortColumn (E.^. StudyTermsKey))
|
||||||
, ("isnew" , SortColumn (StudyTermsKey `E.inList` (unStudyTermsKey <$> Set.toList newKeys)))
|
, ("isnew" , SortColumn (\studyTerm -> studyTerm E.^. StudyTermsKey `E.in_` E.valList (unStudyTermsKey <$> Set.toList newKeys)))
|
||||||
, ("isbad" , SortColumn (StudyTermsKey `E.inList` (unStudyTermsKey <$> Set.toList badKeys)))
|
-- 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))
|
, ("name" , SortColumn (E.^. StudyTermsName))
|
||||||
, ("short" , SortColumn (E.^. StudyTermsShorthand))
|
, ("short" , SortColumn (E.^. StudyTermsShorthand))
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user