Repository navigation
Expand file tree
/
Copy pathExtended.hs
More file actions
84 lines (61 loc) · 1.73 KB
/
Copy pathExtended.hs
File metadata and controls
84 lines (61 loc) · 1.73 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
module Data.Text.Extended
( ToTxt (..),
bquote,
squote,
dquote,
dquoteList,
commaSeparated,
paren,
parenB,
(<~>),
(<>>),
(<<>),
)
where
import Data.Text as DT
import Database.ODBC.SQLServer qualified as ODBC
import Hasura.Prelude
import Language.GraphQL.Draft.Printer qualified as G
import Language.GraphQL.Draft.Syntax qualified as G
import Text.Builder qualified as TB
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 () where
toTxt = tshow
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 '`'
squote :: ToTxt t => t -> Text
squote t = DT.singleton '\'' <> toTxt t <> DT.singleton '\''
dquote :: ToTxt t => t -> Text
dquote t = DT.singleton '"' <> toTxt t <> DT.singleton '"'
paren :: ToTxt t => t -> Text
paren t = "(" <> toTxt t <> ")"
parenB :: TB.Builder -> TB.Builder
parenB t = TB.char '(' <> t <> TB.char ')'
dquoteList :: (ToTxt t, Foldable f) => f t -> Text
dquoteList = DT.intercalate ", " . fmap dquote . toList
commaSeparated :: (ToTxt t, Foldable f) => f t -> Text
commaSeparated = DT.intercalate ", " . fmap toTxt . toList
infixr 6 <>>
(<>>) :: ToTxt t => Text -> t -> Text
(<>>) lTxt a = lTxt <> dquote a
infixr 6 <<>
(<<>) :: ToTxt t => t -> Text -> Text
(<<>) a rTxt = dquote a <> rTxt
infixr 6 <~>
(<~>) :: TB.Builder -> TB.Builder -> TB.Builder
(<~>) l r = l <> TB.char ' ' <> r