Reading and writing binary files

This commit is contained in:
2018-08-08 23:56:16 +03:00
parent 84a838e141
commit 1a8646df46
8 changed files with 153 additions and 18 deletions

View File

@ -96,7 +96,7 @@ users = genTable "users" [ (email :: User HashedPassword -> Email) :- uniqueGen
, (identifier :: User HashedPassword -> UserID) :- autoPrimaryGen ]
-- | Book type
newtype HashDigest = HashDigest { unHex :: Text } deriving Show
newtype HashDigest = HashDigest { unHex :: ByteString } deriving Show
-- XXX: Add an identifier for the book
data Book = Book { identifier :: BookID
, contentHash :: Maybe HashDigest
@ -107,8 +107,8 @@ data Book = Book { identifier :: BookID
deriving (Show, Generic)
instance SqlType HashDigest where
mkLit = LCustom . LText . unHex
fromSql (SqlString x) = HashDigest x
mkLit = LCustom . LBlob . unHex
fromSql (SqlBlob x) = HashDigest x
fromSql _ = error "fromSql: Not a valid hash digest"
defaultValue = mkLit (HashDigest "") -- Doesn't really make sense