diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-20 13:02:02 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-20 13:02:02 +0000 |
commit | 64e3df81b31cc79b035913bda4d093e31bb1955a (patch) | |
tree | 8aad2a9ab446daaff4be91af4838e71698ab3be6 /spec | |
parent | d5beb20783df5f13357dd6d2a55c48c97da578f4 (diff) | |
download | thermoprint-64e3df81b31cc79b035913bda4d093e31bb1955a.tar thermoprint-64e3df81b31cc79b035913bda4d093e31bb1955a.tar.gz thermoprint-64e3df81b31cc79b035913bda4d093e31bb1955a.tar.bz2 thermoprint-64e3df81b31cc79b035913bda4d093e31bb1955a.tar.xz thermoprint-64e3df81b31cc79b035913bda4d093e31bb1955a.zip |
Store Printouts in persistent sql-based dbs
Diffstat (limited to 'spec')
-rw-r--r-- | spec/src/Thermoprint/Printout.hs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/spec/src/Thermoprint/Printout.hs b/spec/src/Thermoprint/Printout.hs index 397a1af..89be802 100644 --- a/spec/src/Thermoprint/Printout.hs +++ b/spec/src/Thermoprint/Printout.hs | |||
@@ -23,13 +23,18 @@ import Data.Text.Lazy (Text) | |||
23 | import Data.ByteString.Lazy (ByteString) | 23 | import Data.ByteString.Lazy (ByteString) |
24 | import qualified Data.ByteString.Lazy as LBS (toStrict) | 24 | import qualified Data.ByteString.Lazy as LBS (toStrict) |
25 | 25 | ||
26 | import qualified Data.ByteString as Strict (ByteString) | ||
27 | |||
26 | import GHC.Generics (Generic) | 28 | import GHC.Generics (Generic) |
27 | import Control.DeepSeq (NFData) | 29 | import Control.DeepSeq (NFData) |
28 | import Data.Aeson (FromJSON(..), ToJSON(..), Value(..)) | 30 | import Data.Aeson (FromJSON(..), ToJSON(..), Value(..)) |
29 | import qualified Data.Aeson as JSON (encode, decode, eitherDecodeStrict') | 31 | import qualified Data.Aeson as JSON (encode, decode, eitherDecodeStrict') |
30 | import Data.Aeson.Types (typeMismatch) | 32 | import Data.Aeson.Types (typeMismatch) |
31 | 33 | ||
34 | import Data.Proxy (Proxy(..)) | ||
35 | |||
32 | import Database.Persist.Class (PersistField(..)) | 36 | import Database.Persist.Class (PersistField(..)) |
37 | import Database.Persist.Sql (PersistFieldSql(..)) | ||
33 | 38 | ||
34 | import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary, genericShrink) | 39 | import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary, genericShrink) |
35 | import Test.QuickCheck.Modifiers (NonNegative(..)) | 40 | import Test.QuickCheck.Modifiers (NonNegative(..)) |
@@ -67,7 +72,10 @@ type Printout = Seq Paragraph | |||
67 | 72 | ||
68 | instance PersistField Printout where | 73 | instance PersistField Printout where |
69 | toPersistValue = toPersistValue . LBS.toStrict . JSON.encode | 74 | toPersistValue = toPersistValue . LBS.toStrict . JSON.encode |
70 | fromPersistValue = first T.pack . JSON.eitherDecodeStrict' <=< fromPersistValue | 75 | fromPersistValue = first T.pack . JSON.eitherDecodeStrict' <=< fromPersistValue |
76 | |||
77 | instance PersistFieldSql Printout where | ||
78 | sqlType _ = sqlType (Proxy :: Proxy Strict.ByteString) | ||
71 | 79 | ||
72 | -- | A 'Paragraph' is a non-seperated sequence of 'Chunk's | 80 | -- | A 'Paragraph' is a non-seperated sequence of 'Chunk's |
73 | type Paragraph = Seq Chunk | 81 | type Paragraph = Seq Chunk |