2021-04-20 19:57:14 +03:00
|
|
|
module Hasura.Backends.MSSQL.SQL.Value where
|
|
|
|
|
|
|
|
import Hasura.Prelude
|
|
|
|
|
|
|
|
import qualified Database.ODBC.SQLServer as ODBC
|
|
|
|
import qualified Hasura.GraphQL.Execute.LiveQuery.Plan as LQP
|
|
|
|
import qualified Hasura.RQL.Types.Column as RQL
|
|
|
|
|
2021-05-10 13:17:54 +03:00
|
|
|
import Data.Text.Encoding (decodeUtf8)
|
|
|
|
|
|
|
|
import Hasura.Backends.MSSQL.Types.Internal (Expression (..), Value)
|
2021-04-20 19:57:14 +03:00
|
|
|
import Hasura.SQL.Backend
|
2021-05-10 13:17:54 +03:00
|
|
|
import Hasura.SQL.Types (toSQLTxt)
|
|
|
|
import Hasura.SQL.Value (TxtEncodedVal (..))
|
2021-04-20 19:57:14 +03:00
|
|
|
|
|
|
|
txtEncodedVal :: Value -> TxtEncodedVal
|
2021-05-10 13:17:54 +03:00
|
|
|
txtEncodedVal ODBC.NullValue = TENull
|
|
|
|
txtEncodedVal (ODBC.ByteStringValue b) = TELit $ decodeUtf8 b
|
|
|
|
txtEncodedVal (ODBC.TextValue t) = TELit t
|
|
|
|
txtEncodedVal val = TELit $ toSQLTxt $ ValueExpression val
|
2021-04-20 19:57:14 +03:00
|
|
|
|
|
|
|
toTxtEncodedVal :: forall f. Functor f => f (RQL.ColumnValue 'MSSQL) -> LQP.ValidatedVariables f
|
|
|
|
toTxtEncodedVal = LQP.ValidatedVariables . fmap (txtEncodedVal . RQL.cvValue)
|