git.iko.soy/typeable/postgresql-simple
on master help sign in
Change (Qualified) Identifier to use Text
a3c2b86Leon P Smith
src/Database/PostgreSQL/Simple/ToField.hs+8−6
@@ -181,15 +181,17 @@ instance ToField (Binary LB.ByteString) where
181 {-# INLINE toField #-}
181 {-# INLINE toField #-}
182
182
183instance ToField Identifier where
183instance ToField Identifier where
184− toField (Identifier bs) = EscapeIdentifier bs
184+ toField (Identifier bs) = EscapeIdentifier (ST.encodeUtf8 bs)
185 {-# INLINE toField #-}
185 {-# INLINE toField #-}
186
186
187instance ToField QualifiedIdentifier where
187instance ToField QualifiedIdentifier where
188− toField (QualifiedIdentifier (Just s) t) = Many [ EscapeIdentifier s
188+ toField (QualifiedIdentifier (Just s) t) =
189+ Many [ EscapeIdentifier (ST.encodeUtf8 s)
189− , Plain (fromChar '.')
190+ , Plain (fromChar '.')
190− , EscapeIdentifier t
191+ , EscapeIdentifier (ST.encodeUtf8 t)
191− ]
192+ ]
192− toField (QualifiedIdentifier Nothing t) = EscapeIdentifier t
193+ toField (QualifiedIdentifier Nothing t) =
194+ EscapeIdentifier (ST.encodeUtf8 t)
193 {-# INLINE toField #-}
195 {-# INLINE toField #-}
194
196
195instance ToField SB.ByteString where
197instance ToField SB.ByteString where
src/Database/PostgreSQL/Simple/Types.hs+16−19
@@ -30,16 +30,18 @@ module Database.PostgreSQL.Simple.Types
30 , Values(..)
30 , Values(..)
31 ) where
31 ) where
32
32
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(..))
43
45
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)
124
126
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)
128−
129−instance IsString Identifier where
130− fromString = Identifier . toByteString . Utf8.fromString
131
130
132instance Hashable Identifier where
131instance Hashable Identifier where
133 hashWithSalt i (Identifier t) = hashWithSalt i t
132 hashWithSalt i (Identifier t) = hashWithSalt i t
134
133
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)
139
138
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)
142
141
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)
145− . toByteString
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)
150
147
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]}