PersistField instance for CI, i.e. case-insensitive DB fields

This commit is contained in:
fr33domlover 2016-05-22 21:43:59 +00:00
parent a0d42f9159
commit 3a65568d8f
2 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,34 @@
{- This file is part of Vervis.
-
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
-
- Copying is an act of love. Please copy, reuse and share.
-
- The author(s) have dedicated all copyright and related and neighboring
- rights to this software to the public domain worldwide. This software is
- distributed without any warranty.
-
- You should have received a copy of the CC0 Public Domain Dedication along
- with this software. If not, see
- <http://creativecommons.org/publicdomain/zero/1.0/>.
-}
-- | 'PersistField' instance for 'CI', for easy case-insensitive DB fields.
module Database.Persist.Class.Local
( TextCI
)
where
import Prelude
import Data.CaseInsensitive (CI)
import Data.Text (Text)
import Database.Persist.Class
import qualified Data.CaseInsensitive as CI
instance (PersistField s, CI.FoldCase s) => PersistField (CI s) where
toPersistValue = toPersistValue . CI.original
fromPersistValue = fmap CI.mk . fromPersistValue
type TextCI = CI Text

View file

@ -60,6 +60,7 @@ library
Data.Text.Lazy.UTF8.Local Data.Text.Lazy.UTF8.Local
Data.Time.Clock.Local Data.Time.Clock.Local
Data.Tree.Local Data.Tree.Local
Database.Persist.Class.Local
Development.DarcsRev Development.DarcsRev
Network.SSH.Local Network.SSH.Local
Text.FilePath.Local Text.FilePath.Local