Skip to content

Commit f0bfbb9

Browse files
committed
Add instance IsString QualifiedIdentifier
1 parent 534799b commit f0bfbb9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Database/PostgreSQL/Simple/Types.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ data QualifiedIdentifier = QualifiedIdentifier (Maybe ByteString) ByteString
139139
instance 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.
143151
newtype PGArray a = PGArray {fromPGArray :: [a]}
144152
deriving (Eq, Ord, Read, Show, Typeable, Functor)

0 commit comments

Comments
 (0)