@@ -30,16 +30,18 @@ module Database.PostgreSQL.Simple.Types
30 , Values(..)
30 , Values(..)
33−import Blaze.ByteString.Builder (toByteString)
33+import Blaze.ByteString.Builder (toByteString)
34−import Control.Arrow (first)
34+import Control.Arrow (first)
35−import Data.ByteString (ByteString)
35+import Data.ByteString (ByteString)
36−import Data.Hashable (Hashable(hashWithSalt))
36+import Data.Hashable (Hashable(hashWithSalt))
37−import Data.Monoid (Monoid(..))
37+import Data.Monoid (Monoid(..))
38−import Data.String (IsString(..))
38+import Data.String (IsString(..))
39−import Data.Typeable (Typeable)
39+import Data.Typeable (Typeable)
40import qualified Blaze.ByteString.Builder.Char.Utf8 as Utf8
40import qualified Blaze.ByteString.Builder.Char.Utf8 as Utf8
41import qualified Data.ByteString as B
41import qualified Data.ByteString as B
42+import Data.Text (Text)
43+import qualified Data.Text as T
42−import Database.PostgreSQL.LibPQ (Oid(..))
44+import Database.PostgreSQL.LibPQ (Oid(..))
44-- | A placeholder for the SQL @NULL@ value.
46-- | A placeholder for the SQL @NULL@ value.
45data Null = Null
47data Null = Null
@@ -123,30 +125,25 @@ newtype Binary a = Binary {fromBinary :: a}
123 deriving (Eq, Ord, Read, Show, Typeable, Functor)
125 deriving (Eq, Ord, Read, Show, Typeable, Functor)
125-- | Wrap text for use as sql identifier, i.e. a table or column name.
127-- | Wrap text for use as sql identifier, i.e. a table or column name.
126−newtype Identifier = Identifier {fromIdentifier :: ByteString}
128+newtype Identifier = Identifier {fromIdentifier :: Text}
127− deriving (Eq, Ord, Read, Show, Typeable)
129+ deriving (Eq, Ord, Read, Show, Typeable, IsString)
129−instance IsString Identifier where
130− fromString = Identifier . toByteString . Utf8.fromString
132instance Hashable Identifier where
131instance Hashable Identifier where
133 hashWithSalt i (Identifier t) = hashWithSalt i t
132 hashWithSalt i (Identifier t) = hashWithSalt i t
135-- | 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
136-- with schema, or column with table.
135-- with schema, or column with table.
137−data QualifiedIdentifier = QualifiedIdentifier (Maybe ByteString) ByteString
136+data QualifiedIdentifier = QualifiedIdentifier (Maybe Text) Text
138 deriving (Eq, Ord, Read, Show, Typeable)
137 deriving (Eq, Ord, Read, Show, Typeable)
140instance Hashable QualifiedIdentifier where
139instance Hashable QualifiedIdentifier where
141 hashWithSalt i (QualifiedIdentifier q t) = hashWithSalt i (q, t)
140 hashWithSalt i (QualifiedIdentifier q t) = hashWithSalt i (q, t)
143instance IsString QualifiedIdentifier where
142instance IsString QualifiedIdentifier where
144− fromString str = let (x,y) = B.break (== 46)
143+ fromString str = let (x,y) = T.break (== '.') (fromString str)
146− . Utf8.fromString $ str
147− in if B.null y
144+ in if T.null y
148 then QualifiedIdentifier Nothing x
145 then QualifiedIdentifier Nothing x
149− else QualifiedIdentifier (Just x) (B.tail y)
146+ else QualifiedIdentifier (Just x) (T.tail y)
151-- | Wrap a list for use as a PostgreSQL array.
148-- | Wrap a list for use as a PostgreSQL array.
152newtype PGArray a = PGArray {fromPGArray :: [a]}
149newtype PGArray a = PGArray {fromPGArray :: [a]}