on dev help sign in
Add double quotes around aliases
2f36f46Petter Rasmussen
squeal-postgresql/src/Squeal/PostgreSQL/Render.hs+5
@@ -22,6 +22,7 @@ module Squeal.PostgreSQL.Render
22 parenthesized
22 parenthesized
23 , (<+>)
23 , (<+>)
24 , commaSeparated
24 , commaSeparated
25+ , doubleQuoted
25 , renderCommaSeparated
26 , renderCommaSeparated
26 , renderCommaSeparatedMaybe
27 , renderCommaSeparatedMaybe
27 , renderNat
28 , renderNat
@@ -48,6 +49,10 @@ str1 <+> str2 = str1 <> " " <> str2
48commaSeparated :: [ByteString] -> ByteString
49commaSeparated :: [ByteString] -> ByteString
49commaSeparated = ByteString.intercalate ", "
50commaSeparated = ByteString.intercalate ", "
50
51
52+-- | Add double quotes around a `ByteString`.
53+doubleQuoted :: ByteString -> ByteString
54+doubleQuoted str = "\"" <> str <> "\""
55+
51-- | Comma separate the renderings of a heterogeneous list.
56-- | Comma separate the renderings of a heterogeneous list.
52renderCommaSeparated
57renderCommaSeparated
53 :: SListI xs
58 :: SListI xs
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+4−2
@@ -110,6 +110,8 @@ import GHC.TypeLits
110
110
111import qualified Generics.SOP.Type.Metadata as Type
111import qualified Generics.SOP.Type.Metadata as Type
112
112
113+import Squeal.PostgreSQL.Render
114+
113-- | `PGType` is the promoted datakind of PostgreSQL types.
115-- | `PGType` is the promoted datakind of PostgreSQL types.
114--
116--
115-- >>> import Squeal.PostgreSQL.Schema
117-- >>> import Squeal.PostgreSQL.Schema
@@ -358,9 +360,9 @@ instance alias1 ~ alias2 => IsLabel alias1 (Alias alias2) where
358 fromLabel = Alias
360 fromLabel = Alias
359
361
360-- | >>> renderAlias #jimbob
362-- | >>> renderAlias #jimbob
361−-- "jimbob"
363+-- "\"jimbob\""
362renderAlias :: KnownSymbol alias => Alias alias -> ByteString
364renderAlias :: KnownSymbol alias => Alias alias -> ByteString
363−renderAlias = fromString . symbolVal
365+renderAlias = doubleQuoted . fromString . symbolVal
364
366
365-- | The `As` operator is used to name an expression. `As` is like a demoted
367-- | The `As` operator is used to name an expression. `As` is like a demoted
366-- version of `:::`.
368-- version of `:::`.