git.iko.soy/typeable/postgresql-simple
on master help sign in
add hashable instance for Identifier and QualifiedIdentifier
commit7899bdc5f8e9f167528e1a617ce2c2ad1a6b26bb authorTobias Florek <tob@butter.sh> dateThu 13 Mar 2014, 10:32 (13 years ago) parent5cc3d00
2 files changed+8
postgresql-simple.cabal+1 src/Database/PostgreSQL/Simple/Types.hs+7
postgresql-simple.cabal+1
@@ -59,6 +59,7 @@ Library
5959 blaze-textual,
6060 bytestring >= 0.9,
6161 containers,
62+ hashable,
6263 postgresql-libpq >= 0.9,
6364 template-haskell,
6465 text >= 0.11.1,
src/Database/PostgreSQL/Simple/Types.hs+7
@@ -32,6 +32,7 @@ module Database.PostgreSQL.Simple.Types
3232import Blaze.ByteString.Builder (toByteString)
3333import Control.Arrow (first)
3434import Data.ByteString (ByteString)
35+import Data.Hashable (Hashable(hashWithSalt))
3536import Data.Monoid (Monoid(..))
3637import Data.String (IsString(..))
3738import Data.Typeable (Typeable)
@@ -127,11 +128,17 @@ newtype Identifier = Identifier {fromIdentifier :: ByteString}
127128instance IsString Identifier where
128129 fromString = Identifier . toByteString . Utf8.fromString
129130
131+instance Hashable Identifier where
132+ hashWithSalt i (Identifier t) = hashWithSalt i t
133+
130134-- | Wrap text for use as (maybe) qualified identifier, i.e. a table
131135-- with schema, or column with table.
132136data QualifiedIdentifier = QualifiedIdentifier (Maybe ByteString) ByteString
133137 deriving (Eq, Ord, Read, Show, Typeable)
134138
139+instance Hashable QualifiedIdentifier where
140+ hashWithSalt i (QualifiedIdentifier q t) = hashWithSalt i (q, t)
141+
135142-- | Wrap a list for use as a PostgreSQL array.
136143newtype PGArray a = PGArray {fromPGArray :: [a]}
137144 deriving (Eq, Ord, Read, Show, Typeable, Functor)