From 3a65568d8fab08c9bf34b4395ed78dbfb6c88abd Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sun, 22 May 2016 21:43:59 +0000 Subject: [PATCH] PersistField instance for CI, i.e. case-insensitive DB fields --- src/Database/Persist/Class/Local.hs | 34 +++++++++++++++++++++++++++++ vervis.cabal | 1 + 2 files changed, 35 insertions(+) create mode 100644 src/Database/Persist/Class/Local.hs diff --git a/src/Database/Persist/Class/Local.hs b/src/Database/Persist/Class/Local.hs new file mode 100644 index 0000000..4ff1cd3 --- /dev/null +++ b/src/Database/Persist/Class/Local.hs @@ -0,0 +1,34 @@ +{- This file is part of Vervis. + - + - Written in 2016 by fr33domlover . + - + - ♡ 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 + - . + -} + +-- | '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 diff --git a/vervis.cabal b/vervis.cabal index ae36fc3..e84bdaa 100644 --- a/vervis.cabal +++ b/vervis.cabal @@ -60,6 +60,7 @@ library Data.Text.Lazy.UTF8.Local Data.Time.Clock.Local Data.Tree.Local + Database.Persist.Class.Local Development.DarcsRev Network.SSH.Local Text.FilePath.Local