I found that I cannot easy use ilike` with my newtype.
I have this:
-- | Represents 'Individual's name.
newtype IndividualName = IndividualName Text
deriving stock (Generic)
deriving newtype
( Show
, Eq
, Ord
, DBType
, DBEq
, DBOrd
, ToJSON
, FromHttpApiData
, ToHttpApiData
, ToSchema
, ToText
)
findIndividuals :: Maybe Text -> Word -> Word -> Tx [IndividualP]
findIndividuals name limit offset =
Sql.transaction () . fmap pure $
toDomain <<$>> Sql.select do
let order = isName >$< Sql.desc
Sql.limit limit . Sql.offset offset . Sql.orderBy order $ do
individuals@IndividualSchema{..} <- Sql.each individualSchema
whenJust name $ \n -> Sql.where_ $ n `Sql.iLike` Sql.unsafeCastExpr isName
pure individuals
The only way to do this I found is to use unsafeCastExpr which seems safe, because under hood it's Text anyway...
Another option could be to to do nSql.iLikefmap toText isName, but there is no Functor for Expr.
I found that I cannot easy use ilike` with my newtype.
I have this:
The only way to do this I found is to use
unsafeCastExpr
which seems safe, because under hood it'sText
anyway... Another option could be to to don
Sql.iLikefmap toText isName
, but there is noFunctor
forExpr
.Wdyt?