diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-23 12:58:14 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-23 12:58:14 +0000 |
commit | 32fd365fb546e7e2ad195b575be4bca457cba6e9 (patch) | |
tree | eb38f4b95654f43907dc3077bb550452d0f8ecb1 /server/src | |
parent | b508a6bd35d28260f307acf8ffde8b7acf843a09 (diff) | |
download | thermoprint-32fd365fb546e7e2ad195b575be4bca457cba6e9.tar thermoprint-32fd365fb546e7e2ad195b575be4bca457cba6e9.tar.gz thermoprint-32fd365fb546e7e2ad195b575be4bca457cba6e9.tar.bz2 thermoprint-32fd365fb546e7e2ad195b575be4bca457cba6e9.tar.xz thermoprint-32fd365fb546e7e2ad195b575be4bca457cba6e9.zip |
cleanup of persistent-instances
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/Thermoprint/Server/Database/Instances.hs | 22 |
1 files changed, 1 insertions, 21 deletions
diff --git a/server/src/Thermoprint/Server/Database/Instances.hs b/server/src/Thermoprint/Server/Database/Instances.hs index f5c22fd..e54f90e 100644 --- a/server/src/Thermoprint/Server/Database/Instances.hs +++ b/server/src/Thermoprint/Server/Database/Instances.hs | |||
@@ -6,28 +6,8 @@ module Thermoprint.Server.Database.Instances where | |||
6 | 6 | ||
7 | import Thermoprint.API (Printout, JobStatus, PrintingError) | 7 | import Thermoprint.API (Printout, JobStatus, PrintingError) |
8 | 8 | ||
9 | import Database.Persist (PersistField(..)) | ||
10 | import Database.Persist.Sql (PersistFieldSql(..)) | ||
11 | import Database.Persist.TH | 9 | import Database.Persist.TH |
12 | 10 | ||
13 | import Control.Monad ((<=<)) | 11 | derivePersistFieldJSON "Printout" |
14 | import Data.Bifunctor | ||
15 | |||
16 | import qualified Data.Aeson as JSON (encode, eitherDecodeStrict') | ||
17 | |||
18 | import Data.ByteString (ByteString) | ||
19 | import qualified Data.ByteString.Lazy as LBS (toStrict) | ||
20 | import qualified Data.Text as T (pack) | ||
21 | |||
22 | import Data.Proxy | ||
23 | |||
24 | -- | Instead of deriving an instance using 'derivePersistField', which would use 'show' and 'read', we write our own by hand in order to use json | ||
25 | instance PersistField Printout where | ||
26 | toPersistValue = toPersistValue . LBS.toStrict . JSON.encode | ||
27 | fromPersistValue = first T.pack . JSON.eitherDecodeStrict' <=< fromPersistValue | ||
28 | |||
29 | instance PersistFieldSql Printout where | ||
30 | sqlType _ = sqlType (Proxy :: Proxy ByteString) | ||
31 | |||
32 | derivePersistField "PrintingError" | 12 | derivePersistField "PrintingError" |
33 | derivePersistField "JobStatus" | 13 | derivePersistField "JobStatus" |