git.iko.soy/typeable/postgresql-simple
on master help sign in
add hashable instance for Identifier and QualifiedIdentifier
7899bdcTobias Florek
postgresql-simple.cabal+1
@@ -59,6 +59,7 @@ Library
59 blaze-textual,
59 blaze-textual,
60 bytestring >= 0.9,
60 bytestring >= 0.9,
61 containers,
61 containers,
62+ hashable,
62 postgresql-libpq >= 0.9,
63 postgresql-libpq >= 0.9,
63 template-haskell,
64 template-haskell,
64 text >= 0.11.1,
65 text >= 0.11.1,
src/Database/PostgreSQL/Simple/Types.hs+7
@@ -32,6 +32,7 @@ module Database.PostgreSQL.Simple.Types
32import Blaze.ByteString.Builder (toByteString)
32import Blaze.ByteString.Builder (toByteString)
33import Control.Arrow (first)
33import Control.Arrow (first)
34import Data.ByteString (ByteString)
34import Data.ByteString (ByteString)
35+import Data.Hashable (Hashable(hashWithSalt))
35import Data.Monoid (Monoid(..))
36import Data.Monoid (Monoid(..))
36import Data.String (IsString(..))
37import Data.String (IsString(..))
37import Data.Typeable (Typeable)
38import Data.Typeable (Typeable)
@@ -127,11 +128,17 @@ newtype Identifier = Identifier {fromIdentifier :: ByteString}
127instance IsString Identifier where
128instance IsString Identifier where
128 fromString = Identifier . toByteString . Utf8.fromString
129 fromString = Identifier . toByteString . Utf8.fromString
129
130
131+instance Hashable Identifier where
132+ hashWithSalt i (Identifier t) = hashWithSalt i t
133+
130-- | Wrap text for use as (maybe) qualified identifier, i.e. a table
134-- | Wrap text for use as (maybe) qualified identifier, i.e. a table
131-- with schema, or column with table.
135-- with schema, or column with table.
132data QualifiedIdentifier = QualifiedIdentifier (Maybe ByteString) ByteString
136data QualifiedIdentifier = QualifiedIdentifier (Maybe ByteString) ByteString
133 deriving (Eq, Ord, Read, Show, Typeable)
137 deriving (Eq, Ord, Read, Show, Typeable)
134
138
139+instance Hashable QualifiedIdentifier where
140+ hashWithSalt i (QualifiedIdentifier q t) = hashWithSalt i (q, t)
141+
135-- | Wrap a list for use as a PostgreSQL array.
142-- | Wrap a list for use as a PostgreSQL array.
136newtype PGArray a = PGArray {fromPGArray :: [a]}
143newtype PGArray a = PGArray {fromPGArray :: [a]}
137 deriving (Eq, Ord, Read, Show, Typeable, Functor)
144 deriving (Eq, Ord, Read, Show, Typeable, Functor)