git.iko.soy/typeable/postgresql-simple
on master help sign in
Add Default type with a ToField instance
9c86eefLeon P Smith
src/Database/PostgreSQL/Simple/ToField.hs+5−1
@@ -33,7 +33,7 @@ import Data.Monoid (mappend)
33import Data.Time (Day, TimeOfDay, LocalTime, UTCTime, ZonedTime)
33import Data.Time (Day, TimeOfDay, LocalTime, UTCTime, ZonedTime)
34import Data.Typeable (Typeable)
34import Data.Typeable (Typeable)
35import Data.Word (Word, Word8, Word16, Word32, Word64)
35import Data.Word (Word, Word8, Word16, Word32, Word64)
36−import Database.PostgreSQL.Simple.Types (Binary(..), In(..), Null)
36+import Database.PostgreSQL.Simple.Types (Binary(..), In(..), Null, Default)
37import qualified Blaze.ByteString.Builder.Char.Utf8 as Utf8
37import qualified Blaze.ByteString.Builder.Char.Utf8 as Utf8
38import qualified Data.ByteString as SB
38import qualified Data.ByteString as SB
39import qualified Data.ByteString.Lazy as LB
39import qualified Data.ByteString.Lazy as LB
@@ -99,6 +99,10 @@ instance ToField Null where
99 toField _ = renderNull
99 toField _ = renderNull
100 {-# INLINE toField #-}
100 {-# INLINE toField #-}
101
101
102+instance ToField Default where
103+ toField _ = Plain (fromByteString "default")
104+ {-# INLINE toField #-}
105+
102instance ToField Bool where
106instance ToField Bool where
103 toField True = Plain (fromByteString "true")
107 toField True = Plain (fromByteString "true")
104 toField False = Plain (fromByteString "false")
108 toField False = Plain (fromByteString "false")
src/Database/PostgreSQL/Simple/Types.hs+5
@@ -16,6 +16,7 @@
16module Database.PostgreSQL.Simple.Types
16module Database.PostgreSQL.Simple.Types
17 (
17 (
18 Null(..)
18 Null(..)
19+ , Default(..)
19 , Only(..)
20 , Only(..)
20 , In(..)
21 , In(..)
21 , Binary(..)
22 , Binary(..)
@@ -43,6 +44,10 @@ instance Eq Null where
43 _ == _ = False
44 _ == _ = False
44 _ /= _ = False
45 _ /= _ = False
45
46
47+-- | A placeholder for the PostgreSQL @DEFAULT@ value.
48+data Default = Default
49+ deriving (Read, Show, Typeable)
50+
46-- | A query string. This type is intended to make it difficult to
51-- | A query string. This type is intended to make it difficult to
47-- construct a SQL query by concatenating string fragments, as that is
52-- construct a SQL query by concatenating string fragments, as that is
48-- an extremely common way to accidentally introduce SQL injection
53-- an extremely common way to accidentally introduce SQL injection