summaryrefslogtreecommitdiff
path: root/hosts/surtr/email/spm/server/Data/UUID
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/UUID
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/UUID')
-rw-r--r--hosts/surtr/email/spm/server/Data/UUID/Instances.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/hosts/surtr/email/spm/server/Data/UUID/Instances.hs b/hosts/surtr/email/spm/server/Data/UUID/Instances.hs
new file mode 100644
index 00000000..b2268c96
--- /dev/null
+++ b/hosts/surtr/email/spm/server/Data/UUID/Instances.hs
@@ -0,0 +1,31 @@
1{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-# LANGUAGE OverloadedStrings #-}
3
4module Data.UUID.Instances () where
5
6import Prelude
7import Database.Persist
8import Database.Persist.Sql
9import Data.UUID (UUID)
10import qualified Data.UUID as UUID
11
12import qualified Data.ByteString.Char8 as CBS
13import qualified Data.Text as Text
14
15import Web.PathPieces
16
17
18instance PersistField UUID where
19 toPersistValue = PersistLiteralEscaped . CBS.pack . UUID.toString
20 fromPersistValue (PersistLiteralEscaped uuidB8) =
21 case UUID.fromString $ CBS.unpack uuidB8 of
22 Just uuid -> Right uuid
23 Nothing -> Left "Invalid UUID"
24 fromPersistValue v = Left $ "Expected PersistLiteral but got ‘" <> Text.pack (show v) <> "’"
25
26instance PersistFieldSql UUID where
27 sqlType _ = SqlOther "uuid"
28
29instance PathPiece UUID where
30 toPathPiece = Text.pack . UUID.toString
31 fromPathPiece = UUID.fromString . Text.unpack