From 64e3df81b31cc79b035913bda4d093e31bb1955a Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 20 Jan 2016 13:02:02 +0000 Subject: Store Printouts in persistent sql-based dbs --- spec/src/Thermoprint/Printout.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'spec/src') 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) import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy as LBS (toStrict) +import qualified Data.ByteString as Strict (ByteString) + import GHC.Generics (Generic) import Control.DeepSeq (NFData) import Data.Aeson (FromJSON(..), ToJSON(..), Value(..)) import qualified Data.Aeson as JSON (encode, decode, eitherDecodeStrict') import Data.Aeson.Types (typeMismatch) +import Data.Proxy (Proxy(..)) + import Database.Persist.Class (PersistField(..)) +import Database.Persist.Sql (PersistFieldSql(..)) import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary, genericShrink) import Test.QuickCheck.Modifiers (NonNegative(..)) @@ -67,7 +72,10 @@ type Printout = Seq Paragraph instance PersistField Printout where toPersistValue = toPersistValue . LBS.toStrict . JSON.encode - fromPersistValue = first T.pack . JSON.eitherDecodeStrict' <=< fromPersistValue + fromPersistValue = first T.pack . JSON.eitherDecodeStrict' <=< fromPersistValue + +instance PersistFieldSql Printout where + sqlType _ = sqlType (Proxy :: Proxy Strict.ByteString) -- | A 'Paragraph' is a non-seperated sequence of 'Chunk's type Paragraph = Seq Chunk -- cgit v1.2.3