Repository navigation
Expand file tree
/
Copy pathExtended.hs
More file actions
98 lines (73 loc) · 2.16 KB
/
Copy pathExtended.hs
File metadata and controls
98 lines (73 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module Data.Text.Extended
( ToTxt(..)
, bquote
, squote
, dquote
, dquoteList
, commaSeparated
, paren
, parenB
, (<->)
, (<~>)
, (<>>)
, (<<>)
) where
import Hasura.Prelude
import qualified Database.ODBC.SQLServer as ODBC
import qualified Language.GraphQL.Draft.Printer as G
import qualified Language.GraphQL.Draft.Syntax as G
import qualified Text.Builder as TB
import Data.Text as DT
class ToTxt a where
toTxt :: a -> Text
instance ToTxt Text where
toTxt = id
{-# INLINE toTxt #-}
instance ToTxt Char where
toTxt = DT.singleton
instance ToTxt G.Name where
toTxt = G.unName
deriving instance ToTxt G.EnumValue
instance ToTxt Void where
toTxt = absurd
instance ToTxt (G.Value Void) where
toTxt = TB.run . G.value
instance ToTxt ODBC.Query where
toTxt = ODBC.renderQuery
bquote :: ToTxt t => t -> Text
bquote t = DT.singleton '`' <> toTxt t <> DT.singleton '`'
{-# INLINE bquote #-}
squote :: ToTxt t => t -> Text
squote t = DT.singleton '\'' <> toTxt t <> DT.singleton '\''
{-# INLINE squote #-}
dquote :: ToTxt t => t -> Text
dquote t = DT.singleton '"' <> toTxt t <> DT.singleton '"'
{-# INLINE dquote #-}
paren :: ToTxt t => t -> Text
paren t = "(" <> toTxt t <> ")"
{-# INLINE paren #-}
parenB :: TB.Builder -> TB.Builder
parenB t = TB.char '(' <> t <> TB.char ')'
{-# INLINE parenB #-}
dquoteList :: (ToTxt t, Foldable f) => f t -> Text
dquoteList = DT.intercalate ", " . fmap dquote . toList
{-# INLINE dquoteList #-}
commaSeparated :: (ToTxt t, Foldable f) => f t -> Text
commaSeparated = DT.intercalate ", " . fmap toTxt . toList
{-# INLINE commaSeparated #-}
infixr 6 <->
(<->) :: ToTxt t => t -> t -> Text
(<->) l r = toTxt l <> DT.singleton ' ' <> toTxt r
{-# INLINE (<->) #-}
infixr 6 <>>
(<>>) :: ToTxt t => Text -> t -> Text
(<>>) lTxt a = lTxt <> dquote a
{-# INLINE (<>>) #-}
infixr 6 <<>
(<<>) :: ToTxt t => t -> Text -> Text
(<<>) a rTxt = dquote a <> rTxt
{-# INLINE (<<>) #-}
infixr 6 <~>
(<~>) :: TB.Builder -> TB.Builder -> TB.Builder
(<~>) l r = l <> TB.char ' ' <> r
{-# INLINE (<~>) #-}