summaryrefslogtreecommitdiff
path: root/hosts/surtr/email/spm/server/Data/CaseInsensitive
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2022-05-19 22:05:02 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2022-05-19 22:05:02 +0200
commit84f2affd66a0ff3947b91a30308cb8e6a8ff7594 (patch)
tree4b05057b68ef6c9e8766b80927221b360d13d167 /hosts/surtr/email/spm/server/Data/CaseInsensitive
parent8f0bf6945a24ea8dac4e8395461bb92f22ab71a0 (diff)
downloadnixos-84f2affd66a0ff3947b91a30308cb8e6a8ff7594.tar
nixos-84f2affd66a0ff3947b91a30308cb8e6a8ff7594.tar.gz
nixos-84f2affd66a0ff3947b91a30308cb8e6a8ff7594.tar.bz2
nixos-84f2affd66a0ff3947b91a30308cb8e6a8ff7594.tar.xz
nixos-84f2affd66a0ff3947b91a30308cb8e6a8ff7594.zip
surtr: ...
Diffstat (limited to 'hosts/surtr/email/spm/server/Data/CaseInsensitive')
-rw-r--r--hosts/surtr/email/spm/server/Data/CaseInsensitive/Instances.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/hosts/surtr/email/spm/server/Data/CaseInsensitive/Instances.hs b/hosts/surtr/email/spm/server/Data/CaseInsensitive/Instances.hs
new file mode 100644
index 00000000..1f3f7a11
--- /dev/null
+++ b/hosts/surtr/email/spm/server/Data/CaseInsensitive/Instances.hs
@@ -0,0 +1,30 @@
1{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-# LANGUAGE OverloadedStrings #-}
3
4module Data.CaseInsensitive.Instances () where
5
6import Prelude
7import Database.Persist
8import Database.Persist.Sql
9
10import Data.CaseInsensitive (CI)
11import qualified Data.CaseInsensitive as CI
12
13import Data.Text (Text)
14import qualified Data.Text as Text
15import qualified Data.Text.Encoding as Text
16
17import Control.Exception
18
19
20instance PersistField (CI Text) where
21 toPersistValue = PersistLiteralEscaped . Text.encodeUtf8 . CI.original
22 fromPersistValue = \case
23 PersistText t -> Right $ CI.mk t
24 PersistLiteralEscaped bs -> case Text.decodeUtf8' bs of
25 Right t -> Right $ CI.mk t
26 Left err -> Left $ "Could not decode PersistLiteral as UTF-8: " <> Text.pack (displayException err)
27 o -> Left $ "Expected PersistText or PersistLiteral but got ‘" <> Text.pack (show o) <> "’"
28
29instance PersistFieldSql (CI Text) where
30 sqlType _ = SqlOther "citext"