git.iko.soy/typeable/postgresql-simple
on master help sign in
Add Default type with a ToField instance
commit9c86eef9f253322e753251622aa03fb5581b55dd authorLeon P Smith <leon@melding-monads.com> dateFri 13 Dec 2013, 18:49 (13 years ago) parent1c4d2f3
2 files changed+10−1
src/Database/PostgreSQL/Simple/ToField.hs+5−1 src/Database/PostgreSQL/Simple/Types.hs+5
src/Database/PostgreSQL/Simple/ToField.hs+5−1
@@ -33,7 +33,7 @@ import Data.Monoid (mappend)
3333import Data.Time (Day, TimeOfDay, LocalTime, UTCTime, ZonedTime)
3434import Data.Typeable (Typeable)
3535import 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)
3737import qualified Blaze.ByteString.Builder.Char.Utf8 as Utf8
3838import qualified Data.ByteString as SB
3939import qualified Data.ByteString.Lazy as LB
@@ -99,6 +99,10 @@ instance ToField Null where
9999 toField _ = renderNull
100100 {-# INLINE toField #-}
101101
102+instance ToField Default where
103+ toField _ = Plain (fromByteString "default")
104+ {-# INLINE toField #-}
105+
102106instance ToField Bool where
103107 toField True = Plain (fromByteString "true")
104108 toField False = Plain (fromByteString "false")
src/Database/PostgreSQL/Simple/Types.hs+5
@@ -16,6 +16,7 @@
1616module Database.PostgreSQL.Simple.Types
1717 (
1818 Null(..)
19+ , Default(..)
1920 , Only(..)
2021 , In(..)
2122 , Binary(..)
@@ -43,6 +44,10 @@ instance Eq Null where
4344 _ == _ = False
4445 _ /= _ = False
4546
47+-- | A placeholder for the PostgreSQL @DEFAULT@ value.
48+data Default = Default
49+ deriving (Read, Show, Typeable)
50+
4651-- | A query string. This type is intended to make it difficult to
4752-- construct a SQL query by concatenating string fragments, as that is
4853-- an extremely common way to accidentally introduce SQL injection