2018-06-27 16:11:32 +03:00
|
|
|
module Data.Text.Extended
|
2020-10-21 19:35:06 +03:00
|
|
|
( ToTxt(..)
|
2020-08-27 19:36:39 +03:00
|
|
|
, bquote
|
2018-06-27 16:11:32 +03:00
|
|
|
, squote
|
|
|
|
, dquote
|
2020-10-21 19:35:06 +03:00
|
|
|
, dquoteList
|
|
|
|
, commaSeparated
|
2018-06-27 16:11:32 +03:00
|
|
|
, paren
|
2020-10-21 19:35:06 +03:00
|
|
|
, parenB
|
2018-06-27 16:11:32 +03:00
|
|
|
, (<->)
|
2020-10-21 19:35:06 +03:00
|
|
|
, (<~>)
|
|
|
|
, (<>>)
|
|
|
|
, (<<>)
|
2018-06-27 16:11:32 +03:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Hasura.Prelude
|
|
|
|
|
2021-02-23 20:37:27 +03:00
|
|
|
import qualified Database.ODBC.SQLServer as ODBC
|
2020-12-21 12:11:37 +03:00
|
|
|
import qualified Language.GraphQL.Draft.Printer as G
|
2021-02-03 19:17:20 +03:00
|
|
|
import qualified Language.GraphQL.Draft.Syntax as G
|
2020-12-21 12:11:37 +03:00
|
|
|
import qualified Text.Builder as TB
|
2020-08-27 19:36:39 +03:00
|
|
|
|
2020-12-21 12:11:37 +03:00
|
|
|
import Data.Text as DT
|
2020-10-21 19:35:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
class ToTxt a where
|
|
|
|
toTxt :: a -> Text
|
|
|
|
|
|
|
|
instance ToTxt Text where
|
|
|
|
toTxt = id
|
|
|
|
{-# INLINE toTxt #-}
|
|
|
|
|
|
|
|
instance ToTxt G.Name where
|
|
|
|
toTxt = G.unName
|
|
|
|
|
|
|
|
deriving instance ToTxt G.EnumValue
|
|
|
|
|
2021-02-03 19:17:20 +03:00
|
|
|
instance ToTxt Void where
|
|
|
|
toTxt = absurd
|
|
|
|
|
2020-12-21 12:11:37 +03:00
|
|
|
instance ToTxt (G.Value Void) where
|
|
|
|
toTxt = TB.run . G.value
|
2020-10-21 19:35:06 +03:00
|
|
|
|
2021-02-23 20:37:27 +03:00
|
|
|
instance ToTxt ODBC.Query where
|
|
|
|
toTxt = ODBC.renderQuery
|
|
|
|
|
|
|
|
|
2020-10-21 19:35:06 +03:00
|
|
|
bquote :: ToTxt t => t -> Text
|
|
|
|
bquote t = DT.singleton '`' <> toTxt t <> DT.singleton '`'
|
2020-08-27 19:36:39 +03:00
|
|
|
{-# INLINE bquote #-}
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2020-10-21 19:35:06 +03:00
|
|
|
squote :: ToTxt t => t -> Text
|
|
|
|
squote t = DT.singleton '\'' <> toTxt t <> DT.singleton '\''
|
2018-06-27 16:11:32 +03:00
|
|
|
{-# INLINE squote #-}
|
|
|
|
|
2020-10-21 19:35:06 +03:00
|
|
|
dquote :: ToTxt t => t -> Text
|
|
|
|
dquote t = DT.singleton '"' <> toTxt t <> DT.singleton '"'
|
2018-06-27 16:11:32 +03:00
|
|
|
{-# INLINE dquote #-}
|
|
|
|
|
2020-10-21 19:35:06 +03:00
|
|
|
paren :: ToTxt t => t -> Text
|
|
|
|
paren t = "(" <> toTxt t <> ")"
|
2018-06-27 16:11:32 +03:00
|
|
|
{-# INLINE paren #-}
|
|
|
|
|
2020-10-21 19:35:06 +03:00
|
|
|
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 #-}
|
|
|
|
|
|
|
|
|
2018-06-27 16:11:32 +03:00
|
|
|
infixr 6 <->
|
2020-10-21 19:35:06 +03:00
|
|
|
(<->) :: ToTxt t => t -> t -> Text
|
|
|
|
(<->) l r = toTxt l <> DT.singleton ' ' <> toTxt r
|
2018-06-27 16:11:32 +03:00
|
|
|
{-# INLINE (<->) #-}
|
2020-10-21 19:35:06 +03:00
|
|
|
|
|
|
|
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 (<~>) #-}
|