2022-08-18 11:59:59 +03:00
|
|
|
module Test.Backend.Postgres.Misc
|
2022-08-18 14:30:54 +03:00
|
|
|
( unpreparedValueToSQLExp,
|
|
|
|
idColumn,
|
2022-08-18 11:59:59 +03:00
|
|
|
nameColumn,
|
|
|
|
descColumn,
|
|
|
|
idColumnBuilder,
|
|
|
|
nameColumnBuilder,
|
|
|
|
descColumnBuilder,
|
|
|
|
textOld,
|
|
|
|
textNew,
|
|
|
|
textOther,
|
|
|
|
integerOne,
|
|
|
|
integerTwo,
|
|
|
|
PG,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2022-08-18 14:30:54 +03:00
|
|
|
import Hasura.Backends.Postgres.SQL.DML qualified as S
|
2022-08-18 11:59:59 +03:00
|
|
|
import Hasura.Backends.Postgres.SQL.Types (PGScalarType (..))
|
2022-08-18 14:30:54 +03:00
|
|
|
import Hasura.Backends.Postgres.SQL.Value (PGScalarValue (..), txtEncoder, withScalarTypeAnn)
|
2022-08-18 11:59:59 +03:00
|
|
|
import Hasura.Prelude
|
2023-04-12 12:04:16 +03:00
|
|
|
import Hasura.RQL.IR.Value (Provenance (Unknown), UnpreparedValue (..))
|
2023-04-24 21:35:48 +03:00
|
|
|
import Hasura.RQL.Types.BackendType (BackendType (Postgres), PostgresKind (Vanilla))
|
2022-08-18 11:59:59 +03:00
|
|
|
import Hasura.RQL.Types.Column (ColumnInfo, ColumnType (..), ColumnValue (..))
|
|
|
|
import Test.Parser.Expectation qualified as Expect
|
|
|
|
|
|
|
|
type PG = 'Postgres 'Vanilla
|
|
|
|
|
2022-08-18 14:30:54 +03:00
|
|
|
unpreparedValueToSQLExp :: UnpreparedValue PG -> S.SQLExp
|
|
|
|
unpreparedValueToSQLExp = \case
|
|
|
|
UVLiteral sqlExp -> sqlExp
|
|
|
|
UVParameter _varInfo cval -> withScalarTypeAnn (go $ cvType cval) (txtEncoder $ cvValue cval)
|
|
|
|
_ -> error "unexpected value"
|
|
|
|
where
|
|
|
|
go :: ColumnType PG -> PGScalarType
|
|
|
|
go = \case
|
|
|
|
ColumnScalar t -> t
|
|
|
|
ColumnEnumReference _ -> error "unexpected enum in translating column type"
|
|
|
|
|
2022-08-18 11:59:59 +03:00
|
|
|
idColumnBuilder :: Expect.ColumnInfoBuilder
|
|
|
|
idColumnBuilder =
|
|
|
|
Expect.ColumnInfoBuilder
|
|
|
|
{ cibName = "id",
|
|
|
|
cibType = ColumnScalar PGInteger,
|
|
|
|
cibNullable = False,
|
|
|
|
cibIsPrimaryKey = True
|
|
|
|
}
|
|
|
|
|
|
|
|
nameColumnBuilder :: Expect.ColumnInfoBuilder
|
|
|
|
nameColumnBuilder =
|
|
|
|
Expect.ColumnInfoBuilder
|
|
|
|
{ cibName = "name",
|
|
|
|
cibType = ColumnScalar PGText,
|
|
|
|
cibNullable = False,
|
|
|
|
cibIsPrimaryKey = False
|
|
|
|
}
|
|
|
|
|
|
|
|
descColumnBuilder :: Expect.ColumnInfoBuilder
|
|
|
|
descColumnBuilder =
|
|
|
|
Expect.ColumnInfoBuilder
|
|
|
|
{ cibName = "description",
|
|
|
|
cibType = ColumnScalar PGText,
|
|
|
|
cibNullable = False,
|
|
|
|
cibIsPrimaryKey = False
|
|
|
|
}
|
|
|
|
|
|
|
|
idColumn :: ColumnInfo PG
|
|
|
|
idColumn = Expect.mkColumnInfo idColumnBuilder
|
|
|
|
|
|
|
|
nameColumn :: ColumnInfo PG
|
|
|
|
nameColumn = Expect.mkColumnInfo nameColumnBuilder
|
|
|
|
|
|
|
|
descColumn :: ColumnInfo PG
|
|
|
|
descColumn = Expect.mkColumnInfo descColumnBuilder
|
|
|
|
|
|
|
|
textOld :: UnpreparedValue PG
|
|
|
|
textOld =
|
2023-04-12 12:04:16 +03:00
|
|
|
UVParameter Unknown $
|
2022-08-18 11:59:59 +03:00
|
|
|
ColumnValue
|
|
|
|
{ cvType = ColumnScalar PGText,
|
|
|
|
cvValue = PGValText "old name"
|
|
|
|
}
|
|
|
|
|
|
|
|
textNew :: UnpreparedValue PG
|
|
|
|
textNew =
|
2023-04-12 12:04:16 +03:00
|
|
|
UVParameter Unknown $
|
2022-08-18 11:59:59 +03:00
|
|
|
ColumnValue
|
|
|
|
{ cvType = ColumnScalar PGText,
|
|
|
|
cvValue = PGValText "new name"
|
|
|
|
}
|
|
|
|
|
|
|
|
textOther :: UnpreparedValue PG
|
|
|
|
textOther =
|
2023-04-12 12:04:16 +03:00
|
|
|
UVParameter Unknown $
|
2022-08-18 11:59:59 +03:00
|
|
|
ColumnValue
|
|
|
|
{ cvType = ColumnScalar PGText,
|
|
|
|
cvValue = PGValText "other"
|
|
|
|
}
|
|
|
|
|
|
|
|
integerOne :: UnpreparedValue PG
|
|
|
|
integerOne =
|
2023-04-12 12:04:16 +03:00
|
|
|
UVParameter Unknown $
|
2022-08-18 11:59:59 +03:00
|
|
|
ColumnValue
|
|
|
|
{ cvType = ColumnScalar PGInteger,
|
|
|
|
cvValue = PGValInteger 1
|
|
|
|
}
|
|
|
|
|
|
|
|
integerTwo :: UnpreparedValue PG
|
|
|
|
integerTwo =
|
2023-04-12 12:04:16 +03:00
|
|
|
UVParameter Unknown $
|
2022-08-18 11:59:59 +03:00
|
|
|
ColumnValue
|
|
|
|
{ cvType = ColumnScalar PGInteger,
|
|
|
|
cvValue = PGValInteger 2
|
|
|
|
}
|