git.iko.soy/typeable/postgresql-simple
on master help sign in
Add instance IsString QualifiedIdentifier
commitf0bfbb9bd2788b4c07d2bd04578a160b46152989 authorLeon P Smith <leon@melding-monads.com> dateMon 17 Mar 2014, 08:39 (13 years ago) parent534799b
1 file changed+8
src/Database/PostgreSQL/Simple/Types.hs+8
src/Database/PostgreSQL/Simple/Types.hs+8
@@ -139,6 +139,14 @@ data QualifiedIdentifier = QualifiedIdentifier (Maybe ByteString) ByteString
139139instance Hashable QualifiedIdentifier where
140140 hashWithSalt i (QualifiedIdentifier q t) = hashWithSalt i (q, t)
141141
142+instance IsString QualifiedIdentifier where
143+ fromString str = let (x,y) = B.break (== 46)
144+ . toByteString
145+ . Utf8.fromString $ str
146+ in if B.null y
147+ then QualifiedIdentifier Nothing x
148+ else QualifiedIdentifier (Just x) (B.tail y)
149+
142150-- | Wrap a list for use as a PostgreSQL array.
143151newtype PGArray a = PGArray {fromPGArray :: [a]}
144152 deriving (Eq, Ord, Read, Show, Typeable, Functor)