mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
server: cleanup references to "pgCol" in common and non-postgres backend code
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3393 GitOrigin-RevId: b45cd83f7c3fbc1656011ee888968743b0bbb736
This commit is contained in:
parent
5419236afd
commit
34c2fb2b66
@ -89,15 +89,15 @@ resolveSource sourceConfig customization =
|
||||
{ _ptmiOid = OID (fromIntegral seconds + index :: Int), -- TODO: The seconds are used for uniqueness. BigQuery doesn't support a "stable" ID for a table.
|
||||
_ptmiColumns =
|
||||
[ RawColumnInfo
|
||||
{ prciName = ColumnName name,
|
||||
prciPosition = position,
|
||||
prciType = restTypeToScalarType type',
|
||||
prciIsNullable =
|
||||
{ rciName = ColumnName name,
|
||||
rciPosition = position,
|
||||
rciType = restTypeToScalarType type',
|
||||
rciIsNullable =
|
||||
case mode of
|
||||
Nullable -> True
|
||||
_ -> False,
|
||||
prciDescription = Nothing,
|
||||
prciMutability = ColumnMutability {_cmIsInsertable = True, _cmIsUpdatable = True}
|
||||
rciDescription = Nothing,
|
||||
rciMutability = ColumnMutability {_cmIsInsertable = True, _cmIsUpdatable = True}
|
||||
}
|
||||
| (position, RestFieldSchema {name, type', mode}) <-
|
||||
zip [1 ..] fields -- TODO: Same trouble as Oid above.
|
||||
|
@ -84,7 +84,7 @@ instance Show Error where
|
||||
--
|
||||
-- A ReaderT is used around this in most of the module too, for
|
||||
-- setting the current entity that a given field name refers to. See
|
||||
-- @fromPGCol@.
|
||||
-- @fromColumn@.
|
||||
newtype FromIr a = FromIr
|
||||
{ unFromIr :: ReaderT FromIrReader (StateT FromIrState (Validate (NonEmpty Error))) a
|
||||
}
|
||||
@ -564,7 +564,7 @@ unfurlAnnotatedOrderByElement ::
|
||||
Ir.AnnotatedOrderByElement 'BigQuery Expression -> WriterT (Seq UnfurledJoin) (ReaderT EntityAlias FromIr) FieldName
|
||||
unfurlAnnotatedOrderByElement =
|
||||
\case
|
||||
Ir.AOCColumn pgColumnInfo -> lift (fromPGColumnInfo pgColumnInfo)
|
||||
Ir.AOCColumn columnInfo -> lift (fromColumnInfo columnInfo)
|
||||
Ir.AOCObjectRelation Rql.RelInfo {riMapping = mapping, riRTable = tableName} annBoolExp annOrderByElementG -> do
|
||||
selectFrom <- lift (lift (fromQualifiedTable tableName))
|
||||
joinAliasEntity <-
|
||||
@ -618,8 +618,8 @@ unfurlAnnotatedOrderByElement =
|
||||
(const (fromAlias selectFrom))
|
||||
( case annAggregateOrderBy of
|
||||
Ir.AAOCount -> pure (CountAggregate StarCountable)
|
||||
Ir.AAOOp text pgColumnInfo -> do
|
||||
fieldName <- fromPGColumnInfo pgColumnInfo
|
||||
Ir.AAOOp text columnInfo -> do
|
||||
fieldName <- fromColumnInfo columnInfo
|
||||
pure (OpAggregate text (ColumnExpression fieldName))
|
||||
)
|
||||
)
|
||||
@ -706,8 +706,8 @@ fromAnnBoolExpFld ::
|
||||
Ir.AnnBoolExpFld 'BigQuery Expression -> ReaderT EntityAlias FromIr Expression
|
||||
fromAnnBoolExpFld =
|
||||
\case
|
||||
Ir.AVColumn pgColumnInfo opExpGs -> do
|
||||
expression <- fmap ColumnExpression (fromPGColumnInfo pgColumnInfo)
|
||||
Ir.AVColumn columnInfo opExpGs -> do
|
||||
expression <- fmap ColumnExpression (fromColumnInfo columnInfo)
|
||||
expressions <- traverse (lift . fromOpExpG expression) opExpGs
|
||||
pure (AndExpression expressions)
|
||||
Ir.AVRelationship Rql.RelInfo {riMapping = mapping, riRTable = table} annBoolExp -> do
|
||||
@ -739,12 +739,12 @@ fromAnnBoolExpFld =
|
||||
}
|
||||
)
|
||||
|
||||
fromPGColumnInfo :: Rql.ColumnInfo 'BigQuery -> ReaderT EntityAlias FromIr FieldName
|
||||
fromPGColumnInfo Rql.ColumnInfo {pgiColumn = ColumnName pgCol} = do
|
||||
fromColumnInfo :: Rql.ColumnInfo 'BigQuery -> ReaderT EntityAlias FromIr FieldName
|
||||
fromColumnInfo Rql.ColumnInfo {ciColumn = ColumnName column} = do
|
||||
EntityAlias {entityAliasText} <- ask
|
||||
pure
|
||||
( FieldName
|
||||
{ fieldName = pgCol,
|
||||
{ fieldName = column,
|
||||
fieldNameEntity = entityAliasText
|
||||
}
|
||||
)
|
||||
@ -811,18 +811,18 @@ data FieldSource
|
||||
-- @
|
||||
-- TAFAgg
|
||||
-- [ ( FieldName {getFieldNameTxt = "count"}
|
||||
-- , AFCount (CTSimple [PGCol {getPGColTxt = "AlbumId"}]))
|
||||
-- , AFCount (NonNullFieldCountable [ColumnName {columnName = "AlbumId"}]))
|
||||
-- , ( FieldName {getFieldNameTxt = "foo"}
|
||||
-- , AFCount (CTSimple [PGCol {getPGColTxt = "AlbumId"}]))
|
||||
-- , AFCount (NonNullFieldCountable [ColumnName {columnName = "AlbumId"}]))
|
||||
-- , ( FieldName {getFieldNameTxt = "max"}
|
||||
-- , AFOp
|
||||
-- (AggregateOp
|
||||
-- { _aoOp = "max"
|
||||
-- , _aoFields =
|
||||
-- [ ( FieldName {getFieldNameTxt = "AlbumId"}
|
||||
-- , CFCol (PGCol {getPGColTxt = "AlbumId"}))
|
||||
-- , CFCol (ColumnName {columnName = "AlbumId"} (ColumnScalar IntegerScalarType)))
|
||||
-- , ( FieldName {getFieldNameTxt = "TrackId"}
|
||||
-- , CFCol (PGCol {getPGColTxt = "TrackId"}))
|
||||
-- , CFCol (ColumnName {columnName = "TrackId"} (ColumnScalar IntegerScalarType)))
|
||||
-- ]
|
||||
-- }))
|
||||
-- ]
|
||||
@ -894,16 +894,16 @@ fromAggregateField aggregateField =
|
||||
Ir.AFCount countType ->
|
||||
CountAggregate <$> case countType of
|
||||
StarCountable -> pure StarCountable
|
||||
NonNullFieldCountable names -> NonNullFieldCountable <$> traverse fromPGCol names
|
||||
DistinctCountable names -> DistinctCountable <$> traverse fromPGCol names
|
||||
NonNullFieldCountable names -> NonNullFieldCountable <$> traverse fromColumn names
|
||||
DistinctCountable names -> DistinctCountable <$> traverse fromColumn names
|
||||
Ir.AFOp Ir.AggregateOp {_aoOp = op, _aoFields = fields} -> do
|
||||
fs <- NE.nonEmpty fields `onNothing` refute (pure MalformedAgg)
|
||||
args <-
|
||||
traverse
|
||||
( \(Rql.FieldName fieldName, pgColFld) -> do
|
||||
( \(Rql.FieldName fieldName, columnField) -> do
|
||||
expression' <-
|
||||
case pgColFld of
|
||||
Ir.CFCol pgCol _columnType -> fmap ColumnExpression (fromPGCol pgCol)
|
||||
case columnField of
|
||||
Ir.CFCol column _columnType -> fmap ColumnExpression (fromColumn column)
|
||||
Ir.CFExp text -> pure (ValueExpression (StringValue text))
|
||||
pure (fieldName, expression')
|
||||
)
|
||||
@ -953,7 +953,7 @@ fromAnnColumnField ::
|
||||
Ir.AnnColumnField 'BigQuery Expression ->
|
||||
ReaderT EntityAlias FromIr Expression
|
||||
fromAnnColumnField _stringifyNumbers annColumnField = do
|
||||
fieldName <- fromPGCol pgCol
|
||||
fieldName <- fromColumn column
|
||||
if asText || False -- TOOD: (Rql.isScalarColumnWhere Psql.isBigNum typ && stringifyNumbers == StringifyNumbers)
|
||||
then pure (ToStringExpression (ColumnExpression fieldName))
|
||||
else case caseBoolExpMaybe of
|
||||
@ -963,7 +963,7 @@ fromAnnColumnField _stringifyNumbers annColumnField = do
|
||||
pure (ConditionalProjection ex' fieldName)
|
||||
where
|
||||
Ir.AnnColumnField
|
||||
{ _acfColumn = pgCol,
|
||||
{ _acfColumn = column,
|
||||
_acfAsText = asText :: Bool,
|
||||
_acfOp = _ :: Maybe (Ir.ColumnOp 'BigQuery), -- TODO: What's this?
|
||||
_acfCaseBoolExpression = caseBoolExpMaybe :: Maybe (Ir.AnnColumnCaseBoolExp 'BigQuery Expression)
|
||||
@ -972,8 +972,8 @@ fromAnnColumnField _stringifyNumbers annColumnField = do
|
||||
-- | This is where a field name "foo" is resolved to a fully qualified
|
||||
-- field name [table].[foo]. The table name comes from EntityAlias in
|
||||
-- the ReaderT.
|
||||
fromPGCol :: ColumnName -> ReaderT EntityAlias FromIr FieldName
|
||||
fromPGCol (ColumnName txt) = do
|
||||
fromColumn :: ColumnName -> ReaderT EntityAlias FromIr FieldName
|
||||
fromColumn (ColumnName txt) = do
|
||||
EntityAlias {entityAliasText} <- ask
|
||||
pure (FieldName {fieldName = txt, fieldNameEntity = entityAliasText})
|
||||
|
||||
@ -1497,9 +1497,9 @@ fromMapping ::
|
||||
ReaderT EntityAlias FromIr [Expression]
|
||||
fromMapping localFrom =
|
||||
traverse
|
||||
( \(remotePgCol, localPgCol) -> do
|
||||
localFieldName <- local (const (fromAlias localFrom)) (fromPGCol localPgCol)
|
||||
remoteFieldName <- fromPGCol remotePgCol
|
||||
( \(remoteColumn, localColumn) -> do
|
||||
localFieldName <- local (const (fromAlias localFrom)) (fromColumn localColumn)
|
||||
remoteFieldName <- fromColumn remoteColumn
|
||||
pure
|
||||
( EqualExpression
|
||||
(ColumnExpression localFieldName)
|
||||
@ -1514,9 +1514,9 @@ fromMappingFieldNames ::
|
||||
ReaderT EntityAlias FromIr [(FieldName, FieldName)]
|
||||
fromMappingFieldNames localFrom =
|
||||
traverse
|
||||
( \(remotePgCol, localPgCol) -> do
|
||||
localFieldName <- local (const localFrom) (fromPGCol localPgCol)
|
||||
remoteFieldName <- fromPGCol remotePgCol
|
||||
( \(remoteColumn, localColumn) -> do
|
||||
localFieldName <- local (const localFrom) (fromColumn localColumn)
|
||||
remoteFieldName <- fromColumn remoteColumn
|
||||
pure
|
||||
( (,)
|
||||
(localFieldName)
|
||||
|
@ -79,7 +79,7 @@ data Error
|
||||
--
|
||||
-- A ReaderT is used around this in most of the module too, for
|
||||
-- setting the current entity that a given field name refers to. See
|
||||
-- @fromPGCol@.
|
||||
-- @fromColumn@.
|
||||
newtype FromIr a = FromIr
|
||||
{ unFromIr :: StateT (Map Text Int) (Validate (NonEmpty Error)) a
|
||||
}
|
||||
@ -394,11 +394,11 @@ unfurlAnnotatedOrderByElement ::
|
||||
WriterT (Seq UnfurledJoin) (ReaderT EntityAlias FromIr) (FieldName, Maybe TSQL.ScalarType)
|
||||
unfurlAnnotatedOrderByElement =
|
||||
\case
|
||||
IR.AOCColumn pgColumnInfo -> do
|
||||
fieldName <- lift (fromPGColumnInfo pgColumnInfo)
|
||||
IR.AOCColumn columnInfo -> do
|
||||
fieldName <- lift (fromColumnInfo columnInfo)
|
||||
pure
|
||||
( fieldName,
|
||||
case IR.pgiType pgColumnInfo of
|
||||
case IR.ciType columnInfo of
|
||||
IR.ColumnScalar t -> Just t
|
||||
-- Above: It is of interest to us whether the type is
|
||||
-- text/ntext/image. See ToQuery for more explanation.
|
||||
@ -460,8 +460,8 @@ unfurlAnnotatedOrderByElement =
|
||||
(const (fromAlias selectFrom))
|
||||
( case annAggregateOrderBy of
|
||||
IR.AAOCount -> pure (CountAggregate StarCountable)
|
||||
IR.AAOOp text pgColumnInfo -> do
|
||||
fieldName <- fromPGColumnInfo pgColumnInfo
|
||||
IR.AAOOp text columnInfo -> do
|
||||
fieldName <- fromColumnInfo columnInfo
|
||||
pure (OpAggregate text (pure (ColumnExpression fieldName)))
|
||||
)
|
||||
)
|
||||
@ -535,8 +535,8 @@ fromAnnBoolExpFld ::
|
||||
ReaderT EntityAlias FromIr Expression
|
||||
fromAnnBoolExpFld =
|
||||
\case
|
||||
IR.AVColumn pgColumnInfo opExpGs -> do
|
||||
expression <- fromColumnInfoForBoolExp pgColumnInfo
|
||||
IR.AVColumn columnInfo opExpGs -> do
|
||||
expression <- fromColumnInfoForBoolExp columnInfo
|
||||
expressions <- traverse (lift . fromOpExpG expression) opExpGs
|
||||
pure (AndExpression expressions)
|
||||
IR.AVRelationship IR.RelInfo {riMapping = mapping, riRTable = table} annBoolExp -> do
|
||||
@ -569,9 +569,9 @@ fromAnnBoolExpFld =
|
||||
-- special handling to ensure that SQL Server won't outright reject
|
||||
-- the comparison. See also 'shouldCastToVarcharMax'.
|
||||
fromColumnInfoForBoolExp :: IR.ColumnInfo 'MSSQL -> ReaderT EntityAlias FromIr Expression
|
||||
fromColumnInfoForBoolExp IR.ColumnInfo {pgiColumn = pgCol, pgiType} = do
|
||||
fieldName <- columnNameToFieldName pgCol <$> ask
|
||||
if shouldCastToVarcharMax pgiType -- See function commentary.
|
||||
fromColumnInfoForBoolExp IR.ColumnInfo {ciColumn = column, ciType} = do
|
||||
fieldName <- columnNameToFieldName column <$> ask
|
||||
if shouldCastToVarcharMax ciType -- See function commentary.
|
||||
then pure (CastExpression (ColumnExpression fieldName) WvarcharType DataLengthMax)
|
||||
else pure (ColumnExpression fieldName)
|
||||
|
||||
@ -583,15 +583,15 @@ shouldCastToVarcharMax :: IR.ColumnType 'MSSQL -> Bool
|
||||
shouldCastToVarcharMax typ =
|
||||
typ == IR.ColumnScalar TextType || typ == IR.ColumnScalar WtextType
|
||||
|
||||
fromPGColumnInfo :: IR.ColumnInfo 'MSSQL -> ReaderT EntityAlias FromIr FieldName
|
||||
fromPGColumnInfo IR.ColumnInfo {pgiColumn = pgCol} =
|
||||
columnNameToFieldName pgCol <$> ask
|
||||
fromColumnInfo :: IR.ColumnInfo 'MSSQL -> ReaderT EntityAlias FromIr FieldName
|
||||
fromColumnInfo IR.ColumnInfo {ciColumn = column} =
|
||||
columnNameToFieldName column <$> ask
|
||||
|
||||
-- entityAlias <- ask
|
||||
-- pure
|
||||
-- (columnNameToFieldName pgCol entityAlias
|
||||
-- (columnNameToFieldName column entityAlias
|
||||
-- FieldName
|
||||
-- {fieldName = PG.getPGColTxt pgCol, fieldNameEntity = entityAliasText})
|
||||
-- {fieldName = columnName column, fieldNameEntity = entityAliasText})
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Sources of projected fields
|
||||
@ -658,10 +658,10 @@ fromAggregateField alias aggregateField =
|
||||
DistinctCountable name -> DistinctCountable $ columnFieldAggEntity name
|
||||
IR.AFOp IR.AggregateOp {_aoOp = op, _aoFields = fields} ->
|
||||
let projections :: [Projection] =
|
||||
fields <&> \(fieldName, pgColFld) ->
|
||||
case pgColFld of
|
||||
IR.CFCol pgCol _pgType ->
|
||||
let fname = columnFieldAggEntity pgCol
|
||||
fields <&> \(fieldName, columnField) ->
|
||||
case columnField of
|
||||
IR.CFCol column _columnType ->
|
||||
let fname = columnFieldAggEntity column
|
||||
in AggregateProjection $ Aliased (OpAggregate op [ColumnExpression fname]) (IR.getFieldNameTxt fieldName)
|
||||
IR.CFExp text ->
|
||||
ExpressionProjection $ Aliased (ValueExpression (ODBC.TextValue text)) (IR.getFieldNameTxt fieldName)
|
||||
@ -719,9 +719,9 @@ fromAnnColumnField ::
|
||||
IR.AnnColumnField 'MSSQL Expression ->
|
||||
ReaderT EntityAlias FromIr Expression
|
||||
fromAnnColumnField _stringifyNumbers annColumnField = do
|
||||
fieldName <- fromPGCol pgCol
|
||||
fieldName <- fromColumn column
|
||||
-- TODO: Handle stringifying large numbers
|
||||
{-(IR.isScalarColumnWhere PG.isBigNum typ && stringifyNumbers == StringifyNumbers)-}
|
||||
{-(IR.isScalarColumnWhere isBigNum typ && stringifyNumbers == StringifyNumbers)-}
|
||||
|
||||
-- for geometry and geography values, the automatic json encoding on sql
|
||||
-- server would fail. So we need to convert it to a format the json encoding
|
||||
@ -738,7 +738,7 @@ fromAnnColumnField _stringifyNumbers annColumnField = do
|
||||
pure (ConditionalExpression ex' (ColumnExpression fieldName) nullValue)
|
||||
where
|
||||
IR.AnnColumnField
|
||||
{ _acfColumn = pgCol,
|
||||
{ _acfColumn = column,
|
||||
_acfType = typ,
|
||||
_acfAsText = _asText :: Bool,
|
||||
_acfOp = _ :: Maybe (IR.ColumnOp 'MSSQL), -- TODO: What's this?
|
||||
@ -748,11 +748,11 @@ fromAnnColumnField _stringifyNumbers annColumnField = do
|
||||
-- | This is where a field name "foo" is resolved to a fully qualified
|
||||
-- field name [table].[foo]. The table name comes from EntityAlias in
|
||||
-- the ReaderT.
|
||||
fromPGCol :: ColumnName -> ReaderT EntityAlias FromIr FieldName
|
||||
fromPGCol pgCol = columnNameToFieldName pgCol <$> ask
|
||||
fromColumn :: ColumnName -> ReaderT EntityAlias FromIr FieldName
|
||||
fromColumn column = columnNameToFieldName column <$> ask
|
||||
|
||||
-- entityAlias <- ask
|
||||
-- pure (columnNameToFieldName pgCol entityAlias -- FieldName {fieldName = PG.getPGColTxt pgCol, fieldNameEntity = entityAliasText}
|
||||
-- pure (columnNameToFieldName column entityAlias -- FieldName {fieldName = columnName column, fieldNameEntity = entityAliasText}
|
||||
-- )
|
||||
|
||||
fieldSourceProjections :: FieldSource -> Projection
|
||||
@ -793,7 +793,7 @@ fieldSourceJoin =
|
||||
-- Joins
|
||||
|
||||
fromObjectRelationSelectG ::
|
||||
Map TableName {-PG.QualifiedTable-} EntityAlias ->
|
||||
Map TableName EntityAlias ->
|
||||
IR.ObjectRelationSelectG 'MSSQL Void Expression ->
|
||||
ReaderT EntityAlias FromIr Join
|
||||
fromObjectRelationSelectG existingJoins annRelationSelectG = do
|
||||
@ -851,18 +851,18 @@ fromObjectRelationSelectG existingJoins annRelationSelectG = do
|
||||
where
|
||||
IR.AnnObjectSelectG
|
||||
{ _aosFields = fields :: IR.AnnFieldsG 'MSSQL Void Expression,
|
||||
_aosTableFrom = tableFrom :: TableName {-PG.QualifiedTable-},
|
||||
_aosTableFrom = tableFrom :: TableName,
|
||||
_aosTableFilter = tableFilter :: IR.AnnBoolExp 'MSSQL Expression
|
||||
} = annObjectSelectG
|
||||
IR.AnnRelationSelectG
|
||||
{ aarRelationshipName,
|
||||
aarColumnMapping = mapping :: HashMap ColumnName ColumnName, -- PG.PGCol PG.PGCol
|
||||
aarColumnMapping = mapping :: HashMap ColumnName ColumnName,
|
||||
aarAnnSelect = annObjectSelectG :: IR.AnnObjectSelectG 'MSSQL Void Expression
|
||||
} = annRelationSelectG
|
||||
|
||||
lookupTableFrom ::
|
||||
Map TableName {-PG.QualifiedTable-} EntityAlias ->
|
||||
{-PG.QualifiedTable-} TableName ->
|
||||
Map TableName EntityAlias ->
|
||||
TableName ->
|
||||
FromIr (Either EntityAlias From)
|
||||
lookupTableFrom existingJoins tableFrom = do
|
||||
case M.lookup tableFrom existingJoins of
|
||||
@ -926,7 +926,7 @@ fromArrayRelationSelectG annRelationSelectG = do
|
||||
where
|
||||
IR.AnnRelationSelectG
|
||||
{ aarRelationshipName,
|
||||
aarColumnMapping = mapping :: HashMap ColumnName ColumnName, -- PG.PGCol PG.PGCol
|
||||
aarColumnMapping = mapping :: HashMap ColumnName ColumnName,
|
||||
aarAnnSelect = annSelectG
|
||||
} = annRelationSelectG
|
||||
|
||||
@ -941,18 +941,18 @@ fromRelName relName =
|
||||
-- We should hope to see e.g. "post.category = category.id" for a
|
||||
-- local table of post and a remote table of category.
|
||||
--
|
||||
-- The left/right columns in @HashMap PG.PGCol PG.PGCol@ corresponds
|
||||
-- The left/right columns in @HashMap ColumnName ColumnName@ corresponds
|
||||
-- to the left/right of @select ... join ...@. Therefore left=remote,
|
||||
-- right=local in this context.
|
||||
fromMapping ::
|
||||
From ->
|
||||
HashMap ColumnName ColumnName -> -- PG.PGCol PG.PGCol
|
||||
HashMap ColumnName ColumnName ->
|
||||
ReaderT EntityAlias FromIr [Expression]
|
||||
fromMapping localFrom =
|
||||
traverse
|
||||
( \(remotePgCol, localPgCol) -> do
|
||||
localFieldName <- local (const (fromAlias localFrom)) (fromPGCol localPgCol)
|
||||
remoteFieldName <- fromPGCol remotePgCol
|
||||
( \(remoteColumn, localColumn) -> do
|
||||
localFieldName <- local (const (fromAlias localFrom)) (fromColumn localColumn)
|
||||
remoteFieldName <- fromColumn remoteColumn
|
||||
pure
|
||||
( OpExpression
|
||||
TSQL.EQ'
|
||||
@ -1075,7 +1075,7 @@ fromInsert IR.AnnInsert {..} =
|
||||
insertRows = normalizeInsertRows (_biIdentityColumns _aiBackendInsert) _aiTableCols $ map (IR.getInsertColumns) _aiInsObj
|
||||
insertColumnNames = maybe [] (map fst) $ listToMaybe insertRows
|
||||
insertValues = map (Values . map snd) insertRows
|
||||
allColumnNames = map (ColumnName . unName . IR.pgiName) _aiTableCols
|
||||
allColumnNames = map (ColumnName . unName . IR.ciName) _aiTableCols
|
||||
insertOutput = Output Inserted $ map OutputColumn allColumnNames
|
||||
tempTable = TempTable tempTableNameInserted allColumnNames
|
||||
in Insert _aiTableName insertColumnNames insertOutput tempTable insertValues
|
||||
@ -1106,10 +1106,10 @@ normalizeInsertRows ::
|
||||
[[(Column 'MSSQL, Expression)]] ->
|
||||
[[(Column 'MSSQL, Expression)]]
|
||||
normalizeInsertRows identityColumnNames tableColumns insertRows =
|
||||
let isIdentityColumn column = IR.pgiColumn column `elem` identityColumnNames
|
||||
let isIdentityColumn column = IR.ciColumn column `elem` identityColumnNames
|
||||
allColumnsWithDefaultValue =
|
||||
-- DEFAULT or NULL are not allowed as explicit identity values.
|
||||
map ((,DefaultExpression) . IR.pgiColumn) $ filter (not . isIdentityColumn) tableColumns
|
||||
map ((,DefaultExpression) . IR.ciColumn) $ filter (not . isIdentityColumn) tableColumns
|
||||
addMissingColumns insertRow =
|
||||
HM.toList $ HM.fromList insertRow `HM.union` HM.fromList allColumnsWithDefaultValue
|
||||
sortByColumn = sortBy (\l r -> compare (fst l) (fst r))
|
||||
@ -1130,7 +1130,7 @@ toMerge tableName insertRows identityColumnNames tableColumns IfMatched {..} = d
|
||||
normalizeInsertRows identityColumnNames tableColumns $
|
||||
map (IR.getInsertColumns) insertRows
|
||||
insertColumnNames = maybe [] (map fst) $ listToMaybe normalizedInsertRows
|
||||
allColumnNames = map (ColumnName . unName . IR.pgiName) tableColumns
|
||||
allColumnNames = map (ColumnName . unName . IR.ciName) tableColumns
|
||||
|
||||
matchConditions <-
|
||||
flip runReaderT (EntityAlias "target") $ -- the table is aliased as "target" in MERGE sql
|
||||
@ -1177,7 +1177,7 @@ fromDelete (IR.AnnDel tableName (permFilter, whereClause) _ allColumns) = do
|
||||
( do
|
||||
permissionsFilter <- fromGBoolExp permFilter
|
||||
whereExpression <- fromGBoolExp whereClause
|
||||
let columnNames = map (ColumnName . unName . IR.pgiName) allColumns
|
||||
let columnNames = map (ColumnName . unName . IR.ciName) allColumns
|
||||
pure
|
||||
Delete
|
||||
{ deleteTable =
|
||||
@ -1200,7 +1200,7 @@ fromUpdate (IR.AnnotatedUpdateG tableName (permFilter, whereClause) _ backendUpd
|
||||
( do
|
||||
permissionsFilter <- fromGBoolExp permFilter
|
||||
whereExpression <- fromGBoolExp whereClause
|
||||
let columnNames = map (ColumnName . unName . IR.pgiName) allColumns
|
||||
let columnNames = map (ColumnName . unName . IR.ciName) allColumns
|
||||
pure
|
||||
Update
|
||||
{ updateTable =
|
||||
@ -1229,16 +1229,16 @@ toSelectIntoTempTable tempTableName fromTable allColumns withConstraints = do
|
||||
-- | Extracts the type and column name of a ColumnInfo
|
||||
columnInfoToUnifiedColumn :: IR.ColumnInfo 'MSSQL -> UnifiedColumn
|
||||
columnInfoToUnifiedColumn colInfo =
|
||||
case IR.pgiType colInfo of
|
||||
case IR.ciType colInfo of
|
||||
IR.ColumnScalar t ->
|
||||
UnifiedColumn
|
||||
{ name = unName $ IR.pgiName colInfo,
|
||||
{ name = unName $ IR.ciName colInfo,
|
||||
type' = t
|
||||
}
|
||||
-- Enum values are represented as text value so they will always be of type text
|
||||
IR.ColumnEnumReference {} ->
|
||||
UnifiedColumn
|
||||
{ name = unName $ IR.pgiName colInfo,
|
||||
{ name = unName $ IR.ciName colInfo,
|
||||
type' = TextType
|
||||
}
|
||||
|
||||
|
@ -156,22 +156,22 @@ transformColumn ::
|
||||
SysColumn ->
|
||||
(RawColumnInfo 'MSSQL, [ForeignKey 'MSSQL])
|
||||
transformColumn columnInfo =
|
||||
let prciName = ColumnName $ scName columnInfo
|
||||
prciPosition = scColumnId columnInfo
|
||||
let rciName = ColumnName $ scName columnInfo
|
||||
rciPosition = scColumnId columnInfo
|
||||
|
||||
prciIsNullable = scIsNullable columnInfo
|
||||
prciDescription = Nothing
|
||||
prciType = parseScalarType $ styName $ scJoinedSysType columnInfo
|
||||
rciIsNullable = scIsNullable columnInfo
|
||||
rciDescription = Nothing
|
||||
rciType = parseScalarType $ styName $ scJoinedSysType columnInfo
|
||||
foreignKeys =
|
||||
scJoinedForeignKeyColumns columnInfo <&> \foreignKeyColumn ->
|
||||
let _fkConstraint = Constraint "fk_mssql" $ OID $ sfkcConstraintObjectId foreignKeyColumn
|
||||
|
||||
schemaName = ssName $ sfkcJoinedReferencedSysSchema foreignKeyColumn
|
||||
_fkForeignTable = TableName (sfkcJoinedReferencedTableName foreignKeyColumn) schemaName
|
||||
_fkColumnMapping = HM.singleton prciName $ ColumnName $ sfkcJoinedReferencedColumnName foreignKeyColumn
|
||||
_fkColumnMapping = HM.singleton rciName $ ColumnName $ sfkcJoinedReferencedColumnName foreignKeyColumn
|
||||
in ForeignKey {..}
|
||||
|
||||
prciMutability = ColumnMutability {_cmIsInsertable = True, _cmIsUpdatable = True}
|
||||
rciMutability = ColumnMutability {_cmIsInsertable = True, _cmIsUpdatable = True}
|
||||
in (RawColumnInfo {..}, foreignKeys)
|
||||
|
||||
transformPrimaryKey :: SysPrimaryKey -> PrimaryKey 'MSSQL (Column 'MSSQL)
|
||||
|
@ -130,8 +130,8 @@ tableInsertMatchColumnsEnum sourceName tableInfo selectPermissions = do
|
||||
pure $
|
||||
P.enum enumName description
|
||||
<$> nonEmpty
|
||||
[ ( define $ pgiName column,
|
||||
pgiColumn column
|
||||
[ ( define $ ciName column,
|
||||
ciColumn column
|
||||
)
|
||||
| column <- columns,
|
||||
isMatchColumnValid column
|
||||
@ -144,5 +144,5 @@ tableInsertMatchColumnsEnum sourceName tableInfo selectPermissions = do
|
||||
isMatchColumnValid :: ColumnInfo 'MSSQL -> Bool
|
||||
isMatchColumnValid = \case
|
||||
-- Unfortunately MSSQL does not support comparison for TEXT types.
|
||||
ColumnInfo {pgiType = ColumnScalar TextType} -> False
|
||||
ColumnInfo {ciType = ColumnScalar TextType} -> False
|
||||
_ -> True
|
||||
|
@ -54,7 +54,7 @@ data Error
|
||||
--
|
||||
-- A ReaderT is used around this in most of the module too, for
|
||||
-- setting the current entity that a given field name refers to. See
|
||||
-- @fromPGCol@.
|
||||
-- @fromColumn@.
|
||||
newtype FromIr a = FromIr
|
||||
{ unFromIr :: StateT (Map Text Int) (Validate (NonEmpty Error)) a
|
||||
}
|
||||
@ -172,8 +172,8 @@ fromAnnBoolExp boolExp = do
|
||||
-- special handling to ensure that SQL Server won't outright reject
|
||||
-- the comparison. See also 'shouldCastToVarcharMax'.
|
||||
fromColumnInfoForBoolExp :: IR.ColumnInfo 'MySQL -> ReaderT EntityAlias FromIr Expression
|
||||
fromColumnInfoForBoolExp IR.ColumnInfo {pgiColumn = pgCol, pgiType = _pgiType} = do
|
||||
fieldName <- columnNameToFieldName pgCol <$> ask
|
||||
fromColumnInfoForBoolExp IR.ColumnInfo {ciColumn = column, ciType = _ciType} = do
|
||||
fieldName <- columnNameToFieldName column <$> ask
|
||||
pure (ColumnExpression fieldName)
|
||||
|
||||
fromAnnBoolExpFld ::
|
||||
@ -181,8 +181,8 @@ fromAnnBoolExpFld ::
|
||||
ReaderT EntityAlias FromIr Expression
|
||||
fromAnnBoolExpFld =
|
||||
\case
|
||||
IR.AVColumn pgColumnInfo opExpGs -> do
|
||||
expression <- fromColumnInfoForBoolExp pgColumnInfo
|
||||
IR.AVColumn columnInfo opExpGs -> do
|
||||
expression <- fromColumnInfoForBoolExp columnInfo
|
||||
expressions <- traverse (lift . fromOpExpG expression) opExpGs
|
||||
pure (AndExpression expressions)
|
||||
IR.AVRelationship IR.RelInfo {riMapping = mapping, riRTable = table} annBoolExp -> do
|
||||
@ -230,9 +230,9 @@ fromMapping ::
|
||||
ReaderT EntityAlias FromIr [Expression]
|
||||
fromMapping localFrom = traverse columnsToEqs . HM.toList
|
||||
where
|
||||
columnsToEqs (remotePgCol, localPgCol) = do
|
||||
localFieldName <- local (const (fromAlias localFrom)) (fromPGCol localPgCol)
|
||||
remoteFieldName <- fromPGCol remotePgCol
|
||||
columnsToEqs (remoteColumn, localColumn) = do
|
||||
localFieldName <- local (const (fromAlias localFrom)) (fromColumn localColumn)
|
||||
remoteFieldName <- fromColumn remoteColumn
|
||||
pure
|
||||
( OpExpression
|
||||
EQ'
|
||||
@ -240,8 +240,8 @@ fromMapping localFrom = traverse columnsToEqs . HM.toList
|
||||
(ColumnExpression remoteFieldName)
|
||||
)
|
||||
|
||||
fromPGCol :: Column -> ReaderT EntityAlias FromIr FieldName
|
||||
fromPGCol pgCol = columnNameToFieldName pgCol <$> ask
|
||||
fromColumn :: Column -> ReaderT EntityAlias FromIr FieldName
|
||||
fromColumn column = columnNameToFieldName column <$> ask
|
||||
|
||||
columnNameToFieldName :: Column -> EntityAlias -> FieldName
|
||||
columnNameToFieldName (Column fieldName) EntityAlias {entityAliasText = fieldNameEntity} =
|
||||
@ -272,9 +272,9 @@ data UnfurledJoin = UnfurledJoin
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
fromPGColumnInfo :: IR.ColumnInfo 'MySQL -> ReaderT EntityAlias FromIr FieldName
|
||||
fromPGColumnInfo IR.ColumnInfo {pgiColumn = pgCol} =
|
||||
columnNameToFieldName pgCol <$> ask
|
||||
fromColumnInfo :: IR.ColumnInfo 'MySQL -> ReaderT EntityAlias FromIr FieldName
|
||||
fromColumnInfo IR.ColumnInfo {ciColumn = column} =
|
||||
columnNameToFieldName column <$> ask
|
||||
|
||||
tableNameText :: TableName -> Text
|
||||
tableNameText (TableName {name}) = name
|
||||
@ -290,11 +290,11 @@ unfurlAnnOrderByElement ::
|
||||
WriterT (Seq UnfurledJoin) (ReaderT EntityAlias FromIr) (FieldName, Maybe ScalarType)
|
||||
unfurlAnnOrderByElement =
|
||||
\case
|
||||
IR.AOCColumn pgColumnInfo -> do
|
||||
fieldName <- lift (fromPGColumnInfo pgColumnInfo)
|
||||
IR.AOCColumn columnInfo -> do
|
||||
fieldName <- lift (fromColumnInfo columnInfo)
|
||||
pure
|
||||
( fieldName,
|
||||
case IR.pgiType pgColumnInfo of
|
||||
case IR.ciType columnInfo of
|
||||
IR.ColumnScalar t -> Just t
|
||||
_ -> Nothing
|
||||
)
|
||||
@ -348,8 +348,8 @@ unfurlAnnOrderByElement =
|
||||
(const (fromAlias selectFrom))
|
||||
( case annAggregateOrderBy of
|
||||
IR.AAOCount -> pure (CountAggregate StarCountable)
|
||||
IR.AAOOp text pgColumnInfo -> do
|
||||
fieldName <- fromPGColumnInfo pgColumnInfo
|
||||
IR.AAOOp text columnInfo -> do
|
||||
fieldName <- fromColumnInfo columnInfo
|
||||
pure (OpAggregate text (pure (ColumnExpression fieldName)))
|
||||
)
|
||||
)
|
||||
@ -441,13 +441,13 @@ fromAnnColumnField ::
|
||||
IR.AnnColumnField 'MySQL Expression ->
|
||||
ReaderT EntityAlias FromIr Expression
|
||||
fromAnnColumnField _stringifyNumbers annColumnField = do
|
||||
fieldName <- fromPGCol pgCol
|
||||
fieldName <- fromColumn column
|
||||
if typ == IR.ColumnScalar MySQL.Geometry
|
||||
then pure $ MethodExpression (ColumnExpression fieldName) "STAsText" []
|
||||
else pure (ColumnExpression fieldName)
|
||||
where
|
||||
IR.AnnColumnField
|
||||
{ _acfColumn = pgCol,
|
||||
{ _acfColumn = column,
|
||||
_acfType = typ,
|
||||
_acfAsText = _asText :: Bool,
|
||||
_acfOp = _ :: Maybe (IR.ColumnOp 'MySQL)
|
||||
@ -463,8 +463,8 @@ fromRelName relName =
|
||||
-- IR.AFExp text -> pure (TextAggregate text)
|
||||
-- IR.AFCount countType -> CountAggregate <$> case countType of
|
||||
-- StarCountable -> pure StarCountable
|
||||
-- NonNullFieldCountable names -> NonNullFieldCountable <$> traverse fromPGCol names
|
||||
-- DistinctCountable names -> DistinctCountable <$> traverse fromPGCol names
|
||||
-- NonNullFieldCountable names -> NonNullFieldCountable <$> traverse fromColumn names
|
||||
-- DistinctCountable names -> DistinctCountable <$> traverse fromColumn names
|
||||
-- IR.AFOp _ -> error "fromAggregatefield: not implemented"
|
||||
|
||||
fromTableAggregateFieldG ::
|
||||
@ -725,7 +725,7 @@ fromSelectRows annSelectG = do
|
||||
selectProjections = OSet.fromList selectProjections,
|
||||
selectFrom = selectFrom,
|
||||
selectJoins = argsJoins <> mapMaybe fieldSourceJoin fieldSources,
|
||||
selectWhere = argsWhere <> Where (if isEmptyExpression filterExpression then [] else [filterExpression]),
|
||||
selectWhere = argsWhere <> Where ([filterExpression | not (isEmptyExpression filterExpression)]),
|
||||
selectSqlOffset = argsOffset,
|
||||
selectSqlTop = permissionBasedTop <> argsTop,
|
||||
selectFinalWantedFields = pure (fieldTextNames fields)
|
||||
@ -847,9 +847,9 @@ fromMappingFieldNames ::
|
||||
ReaderT EntityAlias FromIr [(FieldName, FieldName)]
|
||||
fromMappingFieldNames localFrom =
|
||||
traverse
|
||||
( \(remotePgCol, localPgCol) -> do
|
||||
localFieldName <- local (const localFrom) (fromPGCol localPgCol)
|
||||
remoteFieldName <- fromPGCol remotePgCol
|
||||
( \(remoteColumn, localColumn) -> do
|
||||
localFieldName <- local (const localFrom) (fromColumn localColumn)
|
||||
remoteFieldName <- fromColumn remoteColumn
|
||||
pure
|
||||
( (,)
|
||||
(localFieldName)
|
||||
|
@ -39,12 +39,12 @@ mergeMetadata InformationSchema {..} =
|
||||
{ _ptmiOid = OID 0,
|
||||
_ptmiColumns =
|
||||
[ RawColumnInfo
|
||||
{ prciName = Column isColumnName,
|
||||
prciPosition = fromIntegral isOrdinalPosition,
|
||||
prciType = parseMySQLScalarType isColumnType, -- TODO: This needs to become more precise by considering Field length and character-set
|
||||
prciIsNullable = isIsNullable == "YES", -- ref: https://dev.mysql.com/doc/refman/8.0/en/information-schema-columns-table.html
|
||||
prciDescription = Just $ G.Description isColumnComment,
|
||||
prciMutability = ColumnMutability {_cmIsInsertable = True, _cmIsUpdatable = True}
|
||||
{ rciName = Column isColumnName,
|
||||
rciPosition = fromIntegral isOrdinalPosition,
|
||||
rciType = parseMySQLScalarType isColumnType, -- TODO: This needs to become more precise by considering Field length and character-set
|
||||
rciIsNullable = isIsNullable == "YES", -- ref: https://dev.mysql.com/doc/refman/8.0/en/information-schema-columns-table.html
|
||||
rciDescription = Just $ G.Description isColumnComment,
|
||||
rciMutability = ColumnMutability {_cmIsInsertable = True, _cmIsUpdatable = True}
|
||||
}
|
||||
],
|
||||
_ptmiPrimaryKey =
|
||||
|
@ -611,17 +611,17 @@ mkTriggerQ trn qt@(QualifiedObject schema table) allCols op (SubscribeOpSpec lis
|
||||
mkRowExp $ map (\col -> toExtractor (mkQId opVar strfyNum col) col) columns
|
||||
|
||||
mkQId opVar strfyNum colInfo =
|
||||
toJSONableExp strfyNum (pgiType colInfo) False $
|
||||
SEQIdentifier $ QIdentifier (opToQual opVar) $ toIdentifier $ pgiColumn colInfo
|
||||
toJSONableExp strfyNum (ciType colInfo) False $
|
||||
SEQIdentifier $ QIdentifier (opToQual opVar) $ toIdentifier $ ciColumn colInfo
|
||||
|
||||
-- Generate the SQL expression
|
||||
toExtractor sqlExp column
|
||||
-- If the column type is either 'Geography' or 'Geometry', then after applying the 'ST_AsGeoJSON' function
|
||||
-- to the column, alias the value of the expression with the column name else it uses `st_asgeojson` as
|
||||
-- the column name.
|
||||
| isScalarColumnWhere isGeoType (pgiType column) = Extractor sqlExp (Just $ getAlias column)
|
||||
| isScalarColumnWhere isGeoType (ciType column) = Extractor sqlExp (Just $ getAlias column)
|
||||
| otherwise = Extractor sqlExp Nothing
|
||||
getAlias col = toAlias $ Identifier $ getPGColTxt (pgiColumn col)
|
||||
getAlias col = toAlias $ Identifier $ getPGColTxt (ciColumn col)
|
||||
|
||||
mkAllTriggersQ ::
|
||||
forall pgKind m.
|
||||
|
@ -68,19 +68,19 @@ fetchAndValidateEnumValues pgSourceConfig tableName maybePrimaryKey columnInfos
|
||||
validatePrimaryKey = case maybePrimaryKey of
|
||||
Nothing -> refute [EnumTableMissingPrimaryKey]
|
||||
Just primaryKey -> case _pkColumns primaryKey of
|
||||
column NESeq.:<|| Seq.Empty -> case prciType column of
|
||||
column NESeq.:<|| Seq.Empty -> case rciType column of
|
||||
PGText -> pure column
|
||||
_ -> refute [EnumTableNonTextualPrimaryKey column]
|
||||
columns -> refute [EnumTableMultiColumnPrimaryKey $ map prciName (toList columns)]
|
||||
columns -> refute [EnumTableMultiColumnPrimaryKey $ map rciName (toList columns)]
|
||||
|
||||
validateColumns primaryKeyColumn = do
|
||||
let nonPrimaryKeyColumns = maybe columnInfos (`delete` columnInfos) primaryKeyColumn
|
||||
case nonPrimaryKeyColumns of
|
||||
[] -> pure Nothing
|
||||
[column] -> case prciType column of
|
||||
[column] -> case rciType column of
|
||||
PGText -> pure $ Just column
|
||||
_ -> dispute [EnumTableNonTextualCommentColumn column] $> Nothing
|
||||
columns -> dispute [EnumTableTooManyColumns $ map prciName columns] $> Nothing
|
||||
columns -> dispute [EnumTableTooManyColumns $ map rciName columns] $> Nothing
|
||||
|
||||
showErrors :: [EnumTableIntegrityError ('Postgres pgKind)] -> Text
|
||||
showErrors allErrors =
|
||||
@ -116,8 +116,8 @@ fetchAndValidateEnumValues pgSourceConfig tableName maybePrimaryKey columnInfos
|
||||
<> ")"
|
||||
where
|
||||
typeMismatch description colInfo expected =
|
||||
"the table’s " <> description <> " (" <> prciName colInfo <<> ") must have type "
|
||||
<> expected <<> ", not type " <>> prciType colInfo
|
||||
"the table’s " <> description <> " (" <> rciName colInfo <<> ") must have type "
|
||||
<> expected <<> ", not type " <>> rciType colInfo
|
||||
|
||||
fetchEnumValuesFromDb ::
|
||||
forall pgKind m.
|
||||
@ -128,13 +128,13 @@ fetchEnumValuesFromDb ::
|
||||
m EnumValues
|
||||
fetchEnumValuesFromDb tableName primaryKeyColumn maybeCommentColumn = do
|
||||
let nullExtr = Extractor SENull Nothing
|
||||
commentExtr = maybe nullExtr (mkExtr . prciName) maybeCommentColumn
|
||||
commentExtr = maybe nullExtr (mkExtr . rciName) maybeCommentColumn
|
||||
query =
|
||||
Q.fromBuilder $
|
||||
toSQL
|
||||
mkSelect
|
||||
{ selFrom = Just $ mkSimpleFromExp tableName,
|
||||
selExtr = [mkExtr (prciName primaryKeyColumn), commentExtr]
|
||||
selExtr = [mkExtr (rciName primaryKeyColumn), commentExtr]
|
||||
}
|
||||
rawEnumValues <- liftTx $ Q.withQE defaultTxErrorHandler query () True
|
||||
when (null rawEnumValues) $ dispute [EnumTableNoEnumValues]
|
||||
|
@ -331,16 +331,16 @@ fetchFromColVals ::
|
||||
m [(PGCol, PG.SQLExp)]
|
||||
fetchFromColVals colVal reqCols =
|
||||
forM reqCols $ \ci -> do
|
||||
let valM = Map.lookup (pgiColumn ci) colVal
|
||||
let valM = Map.lookup (ciColumn ci) colVal
|
||||
val <-
|
||||
onNothing valM $
|
||||
throw500 $
|
||||
"column "
|
||||
<> pgiColumn ci <<> " not found in given colVal"
|
||||
<> ciColumn ci <<> " not found in given colVal"
|
||||
let pgColVal = case val of
|
||||
TENull -> PG.SENull
|
||||
TELit t -> PG.SELit t
|
||||
return (pgiColumn ci, pgColVal)
|
||||
return (ciColumn ci, pgColVal)
|
||||
|
||||
mkSQLRow :: Map.HashMap PGCol PG.SQLExp -> [(PGCol, PG.SQLExp)] -> [PG.SQLExp]
|
||||
mkSQLRow defVals withPGCol = map snd $
|
||||
|
@ -248,7 +248,7 @@ mutateAndFetchCols qt cols (cte, p) strfyNum = do
|
||||
tabFrom = FromIdentifier $ FIIdentifier rawAliasIdentifier
|
||||
tabPerm = TablePerm annBoolExpTrue Nothing
|
||||
selFlds = flip map cols $
|
||||
\ci -> (fromCol @('Postgres pgKind) $ pgiColumn ci, mkAnnColumnFieldAsText ci)
|
||||
\ci -> (fromCol @('Postgres pgKind) $ ciColumn ci, mkAnnColumnFieldAsText ci)
|
||||
|
||||
sqlText = Q.fromBuilder $ toSQL selectWith
|
||||
selectWith = S.SelectWith [(S.Alias aliasIdentifier, getMutationCTE cte)] select
|
||||
|
@ -673,14 +673,14 @@ prependOp ::
|
||||
SU.UpdateOperator ('Postgres pgKind) m n (UnpreparedValue ('Postgres pgKind))
|
||||
prependOp = SU.UpdateOperator {..}
|
||||
where
|
||||
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . pgiType
|
||||
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . ciType
|
||||
|
||||
updateOperatorParser tableGQLName tableName columns = do
|
||||
let typedParser columnInfo =
|
||||
fmap P.mkParameter
|
||||
<$> BS.columnParser
|
||||
(pgiType columnInfo)
|
||||
(G.Nullability $ pgiIsNullable columnInfo)
|
||||
(ciType columnInfo)
|
||||
(G.Nullability $ ciIsNullable columnInfo)
|
||||
|
||||
desc = "prepend existing jsonb value of filtered columns with new jsonb value"
|
||||
|
||||
@ -707,14 +707,14 @@ appendOp ::
|
||||
SU.UpdateOperator ('Postgres pgKind) m n (UnpreparedValue ('Postgres pgKind))
|
||||
appendOp = SU.UpdateOperator {..}
|
||||
where
|
||||
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . pgiType
|
||||
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . ciType
|
||||
|
||||
updateOperatorParser tableGQLName tableName columns = do
|
||||
let typedParser columnInfo =
|
||||
fmap P.mkParameter
|
||||
<$> BS.columnParser
|
||||
(pgiType columnInfo)
|
||||
(G.Nullability $ pgiIsNullable columnInfo)
|
||||
(ciType columnInfo)
|
||||
(G.Nullability $ ciIsNullable columnInfo)
|
||||
|
||||
desc = "append existing jsonb value of filtered columns with new jsonb value"
|
||||
SU.updateOperator
|
||||
@ -741,7 +741,7 @@ deleteKeyOp ::
|
||||
SU.UpdateOperator ('Postgres pgKind) m n (UnpreparedValue ('Postgres pgKind))
|
||||
deleteKeyOp = SU.UpdateOperator {..}
|
||||
where
|
||||
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . pgiType
|
||||
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . ciType
|
||||
|
||||
updateOperatorParser tableGQLName tableName columns = do
|
||||
let nullableTextParser _ = fmap P.mkParameter <$> columnParser (ColumnScalar PGText) (G.Nullability True)
|
||||
@ -771,7 +771,7 @@ deleteElemOp ::
|
||||
SU.UpdateOperator ('Postgres pgKind) m n (UnpreparedValue ('Postgres pgKind))
|
||||
deleteElemOp = SU.UpdateOperator {..}
|
||||
where
|
||||
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . pgiType
|
||||
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . ciType
|
||||
|
||||
updateOperatorParser tableGQLName tableName columns = do
|
||||
let nonNullableIntParser _ = fmap P.mkParameter <$> columnParser (ColumnScalar PGInteger) (G.Nullability False)
|
||||
@ -803,7 +803,7 @@ deleteAtPathOp ::
|
||||
SU.UpdateOperator ('Postgres pgKind) m n [UnpreparedValue ('Postgres pgKind)]
|
||||
deleteAtPathOp = SU.UpdateOperator {..}
|
||||
where
|
||||
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . pgiType
|
||||
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . ciType
|
||||
|
||||
updateOperatorParser tableGQLName tableName columns = do
|
||||
let nonNullableTextListParser _ = P.list . fmap P.mkParameter <$> columnParser (ColumnScalar PGText) (G.Nullability False)
|
||||
|
@ -174,7 +174,7 @@ translateBoolExp = \case
|
||||
BoolFld boolExp -> case boolExp of
|
||||
AVColumn colInfo opExps -> do
|
||||
BoolExpCtx {rootReference, currTableReference} <- ask
|
||||
let colFld = fromCol @('Postgres pgKind) $ pgiColumn colInfo
|
||||
let colFld = fromCol @('Postgres pgKind) $ ciColumn colInfo
|
||||
bExps = map (mkFieldCompExp rootReference currTableReference $ LColumn colFld) opExps
|
||||
return $ foldr (S.BEBin S.AndOp) (S.BELit True) bExps
|
||||
AVRelationship (RelInfo _ _ colMapping relTN _ _) nesAnn -> do
|
||||
|
@ -42,11 +42,11 @@ mkSelectExpFromColumnValues qt allCols = \case
|
||||
mkTupsFromColVal colVal =
|
||||
fmap S.TupleExp $
|
||||
forM sortedCols $ \ci -> do
|
||||
let pgCol = pgiColumn ci
|
||||
let pgCol = ciColumn ci
|
||||
val <-
|
||||
onNothing (Map.lookup pgCol colVal) $
|
||||
throw500 $ "column " <> pgCol <<> " not found in returning values"
|
||||
pure $ txtEncodedToSQLExp (pgiType ci) val
|
||||
pure $ txtEncodedToSQLExp (ciType ci) val
|
||||
|
||||
selNoRows =
|
||||
S.mkSelect
|
||||
|
@ -56,8 +56,8 @@ pgColsToSelFlds ::
|
||||
pgColsToSelFlds cols =
|
||||
flip map cols $
|
||||
\pgColInfo ->
|
||||
( fromCol @('Postgres pgKind) $ pgiColumn pgColInfo,
|
||||
mkAnnColumnField (pgiColumn pgColInfo) (pgiType pgColInfo) Nothing Nothing
|
||||
( fromCol @('Postgres pgKind) $ ciColumn pgColInfo,
|
||||
mkAnnColumnField (ciColumn pgColInfo) (ciType pgColInfo) Nothing Nothing
|
||||
-- ^^ Nothing because mutations aren't supported
|
||||
-- with inherited role
|
||||
)
|
||||
@ -151,7 +151,7 @@ mkMutationOutputExp qt allCols preCalAffRows cte mutOutput strfyNum =
|
||||
allColumnsSelect =
|
||||
S.CTESelect $
|
||||
S.mkSelect
|
||||
{ S.selExtr = map (S.mkExtr . pgiColumn) (sortCols allCols),
|
||||
{ S.selExtr = map (S.mkExtr . ciColumn) (sortCols allCols),
|
||||
S.selFrom = Just $ S.mkIdenFromExp mutationResultAlias
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ mkAggregateOrderByAlias :: AnnotatedAggregateOrderBy ('Postgres pgKind) -> S.Ali
|
||||
mkAggregateOrderByAlias =
|
||||
(S.Alias . Identifier) . \case
|
||||
AAOCount -> "count"
|
||||
AAOOp opText col -> opText <> "." <> getPGColTxt (pgiColumn col)
|
||||
AAOOp opText col -> opText <> "." <> getPGColTxt (ciColumn col)
|
||||
|
||||
mkArrayRelationSourcePrefix ::
|
||||
Identifier ->
|
||||
@ -350,8 +350,8 @@ mkAggregateOrderByExtractorAndFields annAggOrderBy =
|
||||
[(FieldName "count", AFCount S.CTStar)]
|
||||
)
|
||||
AAOOp opText pgColumnInfo ->
|
||||
let pgColumn = pgiColumn pgColumnInfo
|
||||
pgType = pgiType pgColumnInfo
|
||||
let pgColumn = ciColumn pgColumnInfo
|
||||
pgType = ciType pgColumnInfo
|
||||
in ( S.Extractor (S.SEFnApp opText [S.SEIdentifier $ toIdentifier pgColumn] Nothing) alias,
|
||||
[ ( FieldName opText,
|
||||
AFOp $
|
||||
@ -372,7 +372,7 @@ mkAnnOrderByAlias ::
|
||||
Identifier -> FieldName -> SimilarArrayFields -> AnnotatedOrderByElement ('Postgres pgKind) v -> S.Alias
|
||||
mkAnnOrderByAlias pfx parAls similarFields = \case
|
||||
AOCColumn pgColumnInfo ->
|
||||
let pgColumn = pgiColumn pgColumnInfo
|
||||
let pgColumn = ciColumn pgColumnInfo
|
||||
obColAls = mkBaseTableColumnAlias pfx pgColumn
|
||||
in S.Alias obColAls
|
||||
-- "pfx.or.relname"."pfx.ob.or.relname.rest" AS "pfx.ob.or.relname.rest"
|
||||
@ -865,7 +865,7 @@ processOrderByItems sourcePrefix' fieldAlias' similarArrayFields distOnCols = \c
|
||||
(ordByAlias,) <$> case annObCol of
|
||||
AOCColumn pgColInfo ->
|
||||
pure $
|
||||
S.mkQIdenExp (mkBaseTableAlias sourcePrefix) $ toIdentifier $ pgiColumn pgColInfo
|
||||
S.mkQIdenExp (mkBaseTableAlias sourcePrefix) $ toIdentifier $ ciColumn pgColInfo
|
||||
AOCObjectRelation relInfo relFilter rest -> withWriteObjectRelation $ do
|
||||
let RelInfo relName _ colMapping relTable _ _ = relInfo
|
||||
relSourcePrefix = mkObjectRelationTableAlias sourcePrefix relName
|
||||
@ -973,7 +973,7 @@ processOrderByItems sourcePrefix' fieldAlias' similarArrayFields distOnCols = \c
|
||||
sortAtNodeAndBase baseColumnOrderBys =
|
||||
let mkBaseOrderByItem (OrderByItemG orderByType columnInfo nullsOrder) =
|
||||
S.OrderByItem
|
||||
(S.SEIdentifier $ toIdentifier $ pgiColumn columnInfo)
|
||||
(S.SEIdentifier $ toIdentifier $ ciColumn columnInfo)
|
||||
orderByType
|
||||
nullsOrder
|
||||
baseOrderByExp = S.OrderByExp $ mkBaseOrderByItem <$> baseColumnOrderBys
|
||||
@ -995,11 +995,11 @@ processOrderByItems sourcePrefix' fieldAlias' similarArrayFields distOnCols = \c
|
||||
AAOCount -> [S.SELit "count", valExp]
|
||||
AAOOp opText colInfo ->
|
||||
[ S.SELit opText,
|
||||
S.applyJsonBuildObj [S.SELit $ getPGColTxt $ pgiColumn colInfo, valExp]
|
||||
S.applyJsonBuildObj [S.SELit $ getPGColTxt $ ciColumn colInfo, valExp]
|
||||
]
|
||||
|
||||
annObColToJSONField valExp = \case
|
||||
AOCColumn pgCol -> [S.SELit $ getPGColTxt $ pgiColumn pgCol, valExp]
|
||||
AOCColumn pgCol -> [S.SELit $ getPGColTxt $ ciColumn pgCol, valExp]
|
||||
AOCObjectRelation relInfo _ obCol ->
|
||||
[ S.SELit $ relNameToTxt $ riName relInfo,
|
||||
S.applyJsonBuildObj $ annObColToJSONField valExp obCol
|
||||
@ -1208,8 +1208,8 @@ processAnnFields sourcePrefix fieldAlias similarArrFields annFields = do
|
||||
mkNodeId :: QualifiedTable -> PrimaryKeyColumns ('Postgres pgKind) -> S.SQLExp
|
||||
mkNodeId (QualifiedObject tableSchema tableName) pkeyColumns =
|
||||
let columnInfoToSQLExp pgColumnInfo =
|
||||
toJSONableExp False (pgiType pgColumnInfo) False $
|
||||
S.mkQIdenExp (mkBaseTableAlias sourcePrefix) $ pgiColumn pgColumnInfo
|
||||
toJSONableExp False (ciType pgColumnInfo) False $
|
||||
S.mkQIdenExp (mkBaseTableAlias sourcePrefix) $ ciColumn pgColumnInfo
|
||||
in -- See Note [Relay Node id].
|
||||
encodeBase64 $
|
||||
flip S.SETyAnn S.textTypeAnn $
|
||||
@ -1532,15 +1532,15 @@ processConnectionSelect sourcePrefixes fieldAlias relAlias colMapping connection
|
||||
S.applyJsonBuildObj $
|
||||
flip concatMap (toList primaryKeyColumns) $
|
||||
\pgColumnInfo ->
|
||||
[ S.SELit $ getPGColTxt $ pgiColumn pgColumnInfo,
|
||||
toJSONableExp False (pgiType pgColumnInfo) False $
|
||||
S.mkQIdenExp (mkBaseTableAlias thisPrefix) $ pgiColumn pgColumnInfo
|
||||
[ S.SELit $ getPGColTxt $ ciColumn pgColumnInfo,
|
||||
toJSONableExp False (ciType pgColumnInfo) False $
|
||||
S.mkQIdenExp (mkBaseTableAlias thisPrefix) $ ciColumn pgColumnInfo
|
||||
]
|
||||
|
||||
primaryKeyColumnExtractors =
|
||||
flip map (toList primaryKeyColumns) $
|
||||
\pgColumnInfo ->
|
||||
let pgColumn = pgiColumn pgColumnInfo
|
||||
let pgColumn = ciColumn pgColumnInfo
|
||||
in ( S.Alias $ mkBaseTableColumnAlias thisPrefix pgColumn,
|
||||
S.mkQIdenExp (mkBaseTableAlias thisPrefix) pgColumn
|
||||
)
|
||||
|
@ -51,6 +51,6 @@ expandOperator infos (column, op) = S.SetExpItem $
|
||||
asJSON e = S.SETyAnn e S.jsonbTypeAnn
|
||||
asArray a = S.SETyAnn (S.SEArray a) S.textArrTypeAnn
|
||||
asNum e = S.SETyAnn e $
|
||||
case find (\info -> pgiColumn info == column) infos <&> pgiType of
|
||||
case find (\info -> ciColumn info == column) infos <&> ciType of
|
||||
Just (ColumnScalar s) -> S.mkTypeAnn $ CollectableTypeScalar s
|
||||
_ -> S.numericTypeAnn
|
||||
|
@ -339,25 +339,25 @@ resolveAsyncActionQuery userInfo annAction =
|
||||
-- TODO (from master):- Avoid using ColumnInfo
|
||||
mkPGColumnInfo (column', columnType) =
|
||||
ColumnInfo
|
||||
{ pgiColumn = column',
|
||||
pgiName = G.unsafeMkName $ getPGColTxt column',
|
||||
pgiPosition = 0,
|
||||
pgiType = ColumnScalar columnType,
|
||||
pgiIsNullable = True,
|
||||
pgiDescription = Nothing,
|
||||
pgiMutability = ColumnMutability False False
|
||||
{ ciColumn = column',
|
||||
ciName = G.unsafeMkName $ getPGColTxt column',
|
||||
ciPosition = 0,
|
||||
ciType = ColumnScalar columnType,
|
||||
ciIsNullable = True,
|
||||
ciDescription = Nothing,
|
||||
ciMutability = ColumnMutability False False
|
||||
}
|
||||
|
||||
tableBoolExpression =
|
||||
let actionIdColumnInfo =
|
||||
ColumnInfo
|
||||
{ pgiColumn = unsafePGCol "id",
|
||||
pgiName = $$(G.litName "id"),
|
||||
pgiPosition = 0,
|
||||
pgiType = ColumnScalar PGUUID,
|
||||
pgiIsNullable = False,
|
||||
pgiDescription = Nothing,
|
||||
pgiMutability = ColumnMutability False False
|
||||
{ ciColumn = unsafePGCol "id",
|
||||
ciName = $$(G.litName "id"),
|
||||
ciPosition = 0,
|
||||
ciType = ColumnScalar PGUUID,
|
||||
ciIsNullable = False,
|
||||
ciDescription = Nothing,
|
||||
ciMutability = ColumnMutability False False
|
||||
}
|
||||
actionIdColumnEq = BoolFld $ AVColumn actionIdColumnInfo [AEQ True $ UVLiteral $ S.SELit $ actionIdToText actionId]
|
||||
sessionVarsColumnInfo = mkPGColumnInfo sessionVarsColumn
|
||||
|
@ -244,7 +244,7 @@ actionOutputFields outputType annotatedObject objectTypes = do
|
||||
tableRelName = RelName $ mkNonEmptyTextUnsafe $ G.unName fieldName
|
||||
columnMapping = Map.fromList $ do
|
||||
(k, v) <- Map.toList fieldMapping
|
||||
pure (unsafePGCol $ G.unName $ unObjectFieldName k, pgiColumn v)
|
||||
pure (unsafePGCol $ G.unName $ unObjectFieldName k, ciColumn v)
|
||||
roleName <- lift askRoleName
|
||||
tablePerms <- hoistMaybe $ RQL.getPermInfoMaybe roleName PASelect tableInfo
|
||||
case relType of
|
||||
@ -282,7 +282,7 @@ mkDefinitionList AnnotatedObjectType {..} =
|
||||
(unsafePGCol . G.unName . unObjectFieldName $ _ofdName,) $
|
||||
case Map.lookup _ofdName fieldReferences of
|
||||
Nothing -> fieldTypeToScalarType $ snd _ofdType
|
||||
Just columnInfo -> unsafePGColumnToBackend $ pgiType columnInfo
|
||||
Just columnInfo -> unsafePGColumnToBackend $ ciType columnInfo
|
||||
where
|
||||
ObjectTypeDefinition {..} = _aotDefinition
|
||||
fieldReferences =
|
||||
|
@ -78,7 +78,7 @@ boolExp sourceName tableInfo selectPermissions = memoizeOn 'boolExp (sourceName,
|
||||
P.fieldOptional fieldName Nothing <$> case fieldInfo of
|
||||
-- field_name: field_type_comparison_exp
|
||||
FIColumn columnInfo ->
|
||||
lift $ fmap (AVColumn columnInfo) <$> comparisonExps @b (pgiType columnInfo)
|
||||
lift $ fmap (AVColumn columnInfo) <$> comparisonExps @b (ciType columnInfo)
|
||||
-- field_name: field_type_bool_exp
|
||||
FIRelationship relationshipInfo -> do
|
||||
remoteTableInfo <- askTableInfo sourceName $ riRTable relationshipInfo
|
||||
|
@ -178,7 +178,7 @@ tableFieldsInput sourceName tableInfo insertPerms =
|
||||
FIComputedField _ -> pure Nothing
|
||||
FIRemoteRelationship _ -> pure Nothing
|
||||
FIColumn columnInfo -> do
|
||||
if (_cmIsInsertable $ pgiMutability columnInfo)
|
||||
if (_cmIsInsertable $ ciMutability columnInfo)
|
||||
then mkColumnParser columnInfo
|
||||
else pure Nothing
|
||||
FIRelationship relInfo -> mkRelationshipParser sourceName relInfo
|
||||
@ -187,14 +187,14 @@ tableFieldsInput sourceName tableInfo insertPerms =
|
||||
ColumnInfo b ->
|
||||
m (Maybe (InputFieldsParser n (Maybe (IR.AnnotatedInsert b (UnpreparedValue b)))))
|
||||
mkColumnParser columnInfo = do
|
||||
let columnName = pgiName columnInfo
|
||||
columnDesc = pgiDescription columnInfo
|
||||
isAllowed = Set.member (pgiColumn columnInfo) (ipiCols insertPerms)
|
||||
let columnName = ciName columnInfo
|
||||
columnDesc = ciDescription columnInfo
|
||||
isAllowed = Set.member (ciColumn columnInfo) (ipiCols insertPerms)
|
||||
whenMaybe isAllowed do
|
||||
fieldParser <- columnParser (pgiType columnInfo) (G.Nullability $ pgiIsNullable columnInfo)
|
||||
fieldParser <- columnParser (ciType columnInfo) (G.Nullability $ ciIsNullable columnInfo)
|
||||
pure $
|
||||
P.fieldOptional columnName columnDesc fieldParser `mapField` \value ->
|
||||
IR.AIColumn (pgiColumn columnInfo, mkParameter value)
|
||||
IR.AIColumn (ciColumn columnInfo, mkParameter value)
|
||||
|
||||
mkDefaultRelationshipParser ::
|
||||
forall b r m n.
|
||||
@ -320,7 +320,7 @@ mkInsertObject objects tableInfo backendInsert insertPerms updatePerms =
|
||||
updateCheck = (fmap . fmap . fmap) partialSQLExpToUnpreparedValue $ upiCheck =<< updatePerms
|
||||
defaultValues =
|
||||
Map.union (partialSQLExpToUnpreparedValue <$> ipiSet insertPerms) $
|
||||
Map.fromList [(column, UVLiteral $ columnDefaultValue @b column) | column <- pgiColumn <$> columns]
|
||||
Map.fromList [(column, UVLiteral $ columnDefaultValue @b column) | column <- ciColumn <$> columns]
|
||||
|
||||
-- delete
|
||||
|
||||
@ -448,10 +448,10 @@ primaryKeysArguments ::
|
||||
primaryKeysArguments tableInfo selectPerms = runMaybeT $ do
|
||||
primaryKeys <- hoistMaybe $ _tciPrimaryKey . _tiCoreInfo $ tableInfo
|
||||
let columns = _pkColumns primaryKeys
|
||||
guard $ all (\c -> pgiColumn c `Map.member` spiCols selectPerms) columns
|
||||
guard $ all (\c -> ciColumn c `Map.member` spiCols selectPerms) columns
|
||||
lift $
|
||||
fmap (BoolAnd . toList) . sequenceA <$> for columns \columnInfo -> do
|
||||
field <- columnParser (pgiType columnInfo) (G.Nullability False)
|
||||
field <- columnParser (ciType columnInfo) (G.Nullability False)
|
||||
pure $
|
||||
BoolFld . AVColumn columnInfo . pure . AEQ True . mkParameter
|
||||
<$> P.field (pgiName columnInfo) (pgiDescription columnInfo) field
|
||||
<$> P.field (ciName columnInfo) (ciDescription columnInfo) field
|
||||
|
@ -57,7 +57,7 @@ orderByExp sourceName tableInfo selectPermissions = memoizeOn 'orderByExp (sourc
|
||||
mkField fieldInfo = runMaybeT $
|
||||
case fieldInfo of
|
||||
FIColumn columnInfo -> do
|
||||
let fieldName = pgiName columnInfo
|
||||
let fieldName = ciName columnInfo
|
||||
pure $
|
||||
P.fieldOptional fieldName Nothing (orderByOperator @b)
|
||||
<&> fmap (pure . mkOrderByItemG @b (IR.AOCColumn columnInfo)) . join
|
||||
@ -164,7 +164,7 @@ orderByAggregation sourceName tableInfo selectPermissions = memoizeOn 'orderByAg
|
||||
|
||||
mkField :: ColumnInfo b -> InputFieldsParser n (Maybe (ColumnInfo b, (BasicOrderType b, NullsOrderType b)))
|
||||
mkField columnInfo =
|
||||
P.fieldOptional (pgiName columnInfo) (pgiDescription columnInfo) (orderByOperator @b)
|
||||
P.fieldOptional (ciName columnInfo) (ciDescription columnInfo) (orderByOperator @b)
|
||||
<&> fmap (columnInfo,) . join
|
||||
|
||||
parseOperator ::
|
||||
|
@ -208,15 +208,15 @@ selectTableByPk ::
|
||||
m (Maybe (FieldParser n (SelectExp b)))
|
||||
selectTableByPk sourceName tableInfo fieldName description selectPermissions = runMaybeT do
|
||||
primaryKeys <- hoistMaybe $ fmap _pkColumns . _tciPrimaryKey . _tiCoreInfo $ tableInfo
|
||||
guard $ all (\c -> pgiColumn c `Map.member` spiCols selectPermissions) primaryKeys
|
||||
guard $ all (\c -> ciColumn c `Map.member` spiCols selectPermissions) primaryKeys
|
||||
lift $ memoizeOn 'selectTableByPk (sourceName, tableName, fieldName) do
|
||||
stringifyNum <- asks $ qcStringifyNum . getter
|
||||
argsParser <-
|
||||
sequenceA <$> for primaryKeys \columnInfo -> do
|
||||
field <- columnParser (pgiType columnInfo) (G.Nullability $ pgiIsNullable columnInfo)
|
||||
field <- columnParser (ciType columnInfo) (G.Nullability $ ciIsNullable columnInfo)
|
||||
pure $
|
||||
BoolFld . AVColumn columnInfo . pure . AEQ True . mkParameter
|
||||
<$> P.field (pgiName columnInfo) (pgiDescription columnInfo) field
|
||||
<$> P.field (ciName columnInfo) (ciDescription columnInfo) field
|
||||
selectionSetParser <- tableSelectionSet sourceName tableInfo selectPermissions
|
||||
pure $
|
||||
P.subselection fieldName description argsParser selectionSetParser
|
||||
@ -697,7 +697,7 @@ defaultTableArgs sourceName tableInfo selectPermissions = do
|
||||
initOrderBys = take colsLen $ NE.toList orderByCols
|
||||
initOrdByCols = flip mapMaybe initOrderBys $ \ob ->
|
||||
case IR.obiColumn ob of
|
||||
IR.AOCColumn pgCol -> Just $ pgiColumn pgCol
|
||||
IR.AOCColumn columnInfo -> Just $ ciColumn columnInfo
|
||||
_ -> Nothing
|
||||
isValid =
|
||||
(colsLen == length initOrdByCols)
|
||||
@ -861,11 +861,11 @@ tableConnectionArgs pkeyColumns sourceName tableInfo selectPermissions = do
|
||||
appendPrimaryKeyOrderBy :: NonEmpty (IR.AnnotatedOrderByItemG b v) -> NonEmpty (IR.AnnotatedOrderByItemG b v)
|
||||
appendPrimaryKeyOrderBy orderBys@(h NE.:| t) =
|
||||
let orderByColumnNames =
|
||||
orderBys ^.. traverse . to IR.obiColumn . IR._AOCColumn . to pgiColumn
|
||||
pkeyOrderBys = flip mapMaybe (toList pkeyColumns) $ \pgColumnInfo ->
|
||||
if pgiColumn pgColumnInfo `elem` orderByColumnNames
|
||||
orderBys ^.. traverse . to IR.obiColumn . IR._AOCColumn . to ciColumn
|
||||
pkeyOrderBys = flip mapMaybe (toList pkeyColumns) $ \columnInfo ->
|
||||
if ciColumn columnInfo `elem` orderByColumnNames
|
||||
then Nothing
|
||||
else Just $ IR.OrderByItemG Nothing (IR.AOCColumn pgColumnInfo) Nothing
|
||||
else Just $ IR.OrderByItemG Nothing (IR.AOCColumn columnInfo) Nothing
|
||||
in h NE.:| (t <> pkeyOrderBys)
|
||||
|
||||
parseConnectionSplit ::
|
||||
@ -877,17 +877,17 @@ tableConnectionArgs pkeyColumns sourceName tableInfo selectPermissions = do
|
||||
cursorValue <- J.eitherDecode cursorSplit `onLeft` const throwInvalidCursor
|
||||
case maybeOrderBys of
|
||||
Nothing -> forM (NESeq.toNonEmpty pkeyColumns) $
|
||||
\pgColumnInfo -> do
|
||||
let columnJsonPath = [J.Key $ toTxt $ pgiColumn pgColumnInfo]
|
||||
columnType = pgiType pgColumnInfo
|
||||
pgColumnValue <-
|
||||
\columnInfo -> do
|
||||
let columnJsonPath = [J.Key $ toTxt $ ciColumn columnInfo]
|
||||
columnType = ciType columnInfo
|
||||
columnValue <-
|
||||
iResultToMaybe (executeJSONPath columnJsonPath cursorValue)
|
||||
`onNothing` throwInvalidCursor
|
||||
pgValue <- liftQErr $ parseScalarValueColumnType columnType pgColumnValue
|
||||
pgValue <- liftQErr $ parseScalarValueColumnType columnType columnValue
|
||||
let unresolvedValue = UVParameter Nothing $ ColumnValue columnType pgValue
|
||||
pure $
|
||||
IR.ConnectionSplit splitKind unresolvedValue $
|
||||
IR.OrderByItemG Nothing (IR.AOCColumn pgColumnInfo) Nothing
|
||||
IR.OrderByItemG Nothing (IR.AOCColumn columnInfo) Nothing
|
||||
Just orderBys ->
|
||||
forM orderBys $ \orderBy -> do
|
||||
let IR.OrderByItemG orderType annObCol nullsOrder = orderBy
|
||||
@ -906,11 +906,11 @@ tableConnectionArgs pkeyColumns sourceName tableInfo selectPermissions = do
|
||||
|
||||
mkAggregateOrderByPath = \case
|
||||
IR.AAOCount -> [J.Key "count"]
|
||||
IR.AAOOp t col -> [J.Key t, J.Key $ toTxt $ pgiColumn col]
|
||||
IR.AAOOp t col -> [J.Key t, J.Key $ toTxt $ ciColumn col]
|
||||
|
||||
getPathFromOrderBy = \case
|
||||
IR.AOCColumn pgColInfo ->
|
||||
let pathElement = J.Key $ toTxt $ pgiColumn pgColInfo
|
||||
IR.AOCColumn columnInfo ->
|
||||
let pathElement = J.Key $ toTxt $ ciColumn columnInfo
|
||||
in [pathElement]
|
||||
IR.AOCObjectRelation relInfo _ obCol ->
|
||||
let pathElement = J.Key $ relNameToTxt $ riName relInfo
|
||||
@ -926,7 +926,7 @@ tableConnectionArgs pkeyColumns sourceName tableInfo selectPermissions = do
|
||||
J.Key (fieldNameText <> "_aggregate") : mkAggregateOrderByPath aggOb
|
||||
|
||||
getOrderByColumnType = \case
|
||||
IR.AOCColumn pgColInfo -> pgiType pgColInfo
|
||||
IR.AOCColumn columnInfo -> ciType columnInfo
|
||||
IR.AOCObjectRelation _ _ obCol -> getOrderByColumnType obCol
|
||||
IR.AOCArrayAggregation _ _ aggOb -> aggregateOrderByColumnType aggOb
|
||||
IR.AOCComputedField cfob ->
|
||||
@ -936,7 +936,7 @@ tableConnectionArgs pkeyColumns sourceName tableInfo selectPermissions = do
|
||||
where
|
||||
aggregateOrderByColumnType = \case
|
||||
IR.AAOCount -> ColumnScalar (aggregateOrderByCountType @b)
|
||||
IR.AAOOp _ colInfo -> pgiType colInfo
|
||||
IR.AAOOp _ colInfo -> ciType colInfo
|
||||
|
||||
-- | Aggregation fields
|
||||
--
|
||||
@ -998,20 +998,20 @@ tableAggregationFields sourceName tableInfo selectPermissions = memoizeOn 'table
|
||||
| otherwise = traverse \columnInfo ->
|
||||
pure $
|
||||
P.selection_
|
||||
(pgiName columnInfo)
|
||||
(pgiDescription columnInfo)
|
||||
(ciName columnInfo)
|
||||
(ciDescription columnInfo)
|
||||
(P.nullable P.float)
|
||||
$> IR.CFCol (pgiColumn columnInfo) (pgiType columnInfo)
|
||||
$> IR.CFCol (ciColumn columnInfo) (ciType columnInfo)
|
||||
|
||||
mkColumnAggField :: ColumnInfo b -> m (FieldParser n (IR.ColFld b))
|
||||
mkColumnAggField columnInfo = do
|
||||
field <- columnParser (pgiType columnInfo) (G.Nullability True)
|
||||
field <- columnParser (ciType columnInfo) (G.Nullability True)
|
||||
pure $
|
||||
P.selection_
|
||||
(pgiName columnInfo)
|
||||
(pgiDescription columnInfo)
|
||||
(ciName columnInfo)
|
||||
(ciDescription columnInfo)
|
||||
field
|
||||
$> IR.CFCol (pgiColumn columnInfo) (pgiType columnInfo)
|
||||
$> IR.CFCol (ciColumn columnInfo) (ciType columnInfo)
|
||||
|
||||
countField :: m (FieldParser n (IR.AggregateField b))
|
||||
countField = do
|
||||
@ -1062,8 +1062,8 @@ fieldSelection sourceName table maybePkeyColumns fieldInfo selectPermissions = d
|
||||
FIColumn columnInfo ->
|
||||
maybeToList <$> runMaybeT do
|
||||
queryType <- asks $ qcQueryType . getter
|
||||
let columnName = pgiColumn columnInfo
|
||||
fieldName = pgiName columnInfo
|
||||
let columnName = ciColumn columnInfo
|
||||
fieldName = ciName columnInfo
|
||||
if fieldName == $$(G.litName "id") && queryType == ET.QueryRelay
|
||||
then do
|
||||
xRelayInfo <- hoistMaybe $ relayExtension @b
|
||||
@ -1076,7 +1076,7 @@ fieldSelection sourceName table maybePkeyColumns fieldInfo selectPermissions = d
|
||||
let caseBoolExp = join $ Map.lookup columnName (spiCols selectPermissions)
|
||||
let caseBoolExpUnpreparedValue =
|
||||
(fmap . fmap) partialSQLExpToUnpreparedValue <$> caseBoolExp
|
||||
let pathArg = jsonPathArg $ pgiType columnInfo
|
||||
let pathArg = jsonPathArg $ ciType columnInfo
|
||||
-- In an inherited role, when a column is part of all the select
|
||||
-- permissions which make up the inherited role then the nullability
|
||||
-- of the field is determined by the nullability of the DB column
|
||||
@ -1096,11 +1096,11 @@ fieldSelection sourceName table maybePkeyColumns fieldInfo selectPermissions = d
|
||||
-- The above is the paper which talks about the idea of cell-level
|
||||
-- authorization and multiple roles. The paper says that we should only
|
||||
-- allow the case analysis only on nullable columns.
|
||||
nullability = pgiIsNullable columnInfo || isJust caseBoolExp
|
||||
field <- lift $ columnParser (pgiType columnInfo) (G.Nullability nullability)
|
||||
nullability = ciIsNullable columnInfo || isJust caseBoolExp
|
||||
field <- lift $ columnParser (ciType columnInfo) (G.Nullability nullability)
|
||||
pure $
|
||||
P.selection fieldName (pgiDescription columnInfo) pathArg field
|
||||
<&> IR.mkAnnColumnField (pgiColumn columnInfo) (pgiType columnInfo) caseBoolExpUnpreparedValue
|
||||
P.selection fieldName (ciDescription columnInfo) pathArg field
|
||||
<&> IR.mkAnnColumnField (ciColumn columnInfo) (ciType columnInfo) caseBoolExpUnpreparedValue
|
||||
FIRelationship relationshipInfo ->
|
||||
concat . maybeToList <$> relationshipField sourceName table relationshipInfo
|
||||
FIComputedField computedFieldInfo ->
|
||||
@ -1170,7 +1170,7 @@ relationshipField sourceName table RelInfo {..} = runMaybeT do
|
||||
colInfo <-
|
||||
traverse findColumn columns
|
||||
`onNothing` throw500 "could not find column info in schema cache"
|
||||
pure $ boolToNullable $ any pgiIsNullable colInfo
|
||||
pure $ boolToNullable $ any ciIsNullable colInfo
|
||||
-- Manual or reverse relationships are always nullable
|
||||
_ -> pure Nullable
|
||||
pure $
|
||||
@ -1617,7 +1617,7 @@ nodeField = do
|
||||
|
||||
unless (null nonAlignedPkColumns) $
|
||||
throwInvalidNodeId $
|
||||
"primary key columns " <> dquoteList (map pgiColumn nonAlignedPkColumns) <> " are missing"
|
||||
"primary key columns " <> dquoteList (map ciColumn nonAlignedPkColumns) <> " are missing"
|
||||
|
||||
unless (null nonAlignedColumnValues) $
|
||||
throwInvalidNodeId $
|
||||
@ -1630,9 +1630,9 @@ nodeField = do
|
||||
fmap IR.BoolAnd $
|
||||
for allTuples $ \(columnInfo, columnValue) -> do
|
||||
let modifyErrFn t =
|
||||
"value of column " <> pgiColumn columnInfo
|
||||
"value of column " <> ciColumn columnInfo
|
||||
<<> " in node id: " <> t
|
||||
pgColumnType = pgiType columnInfo
|
||||
pgColumnType = ciType columnInfo
|
||||
pgValue <- modifyErr modifyErrFn $ parseScalarValueColumnType pgColumnType columnValue
|
||||
let unpreparedValue = UVParameter Nothing $ ColumnValue pgColumnType pgValue
|
||||
pure $ IR.BoolFld $ IR.AVColumn columnInfo [IR.AEQ True unpreparedValue]
|
||||
|
@ -74,8 +74,8 @@ tableSelectColumnsEnum sourceName tableInfo selectPermissions = do
|
||||
pure $
|
||||
P.enum enumName description
|
||||
<$> nonEmpty
|
||||
[ ( define $ pgiName column,
|
||||
pgiColumn column
|
||||
[ ( define $ ciName column,
|
||||
ciColumn column
|
||||
)
|
||||
| column <- columns
|
||||
]
|
||||
@ -102,7 +102,7 @@ tableUpdateColumnsEnum tableInfo updatePermissions = do
|
||||
enumDesc = Just $ G.Description $ "update columns of table " <>> tableName
|
||||
enumValues = do
|
||||
column <- columns
|
||||
pure (define $ pgiName column, pgiColumn column)
|
||||
pure (define $ ciName column, ciColumn column)
|
||||
pure $ P.enum enumName enumDesc <$> nonEmpty enumValues
|
||||
where
|
||||
define name = P.Definition name (Just $ G.Description "column name") P.EnumValueInfo
|
||||
@ -157,7 +157,7 @@ tableSelectFields sourceName tableInfo permissions = do
|
||||
filterM canBeSelected $ Map.elems tableFields
|
||||
where
|
||||
canBeSelected (FIColumn columnInfo) =
|
||||
pure $ Map.member (pgiColumn columnInfo) (spiCols permissions)
|
||||
pure $ Map.member (ciColumn columnInfo) (spiCols permissions)
|
||||
canBeSelected (FIRelationship relationshipInfo) = do
|
||||
tableInfo' <- askTableInfo sourceName $ riRTable relationshipInfo
|
||||
isJust <$> tableSelectPermissions @b tableInfo'
|
||||
@ -206,6 +206,6 @@ tableUpdateColumns tableInfo permissions = pure $ filter isUpdatable $ tableColu
|
||||
isUpdatable :: ColumnInfo b -> Bool
|
||||
isUpdatable columnInfo = columnIsUpdatable && columnIsPermitted && columnHasNoPreset
|
||||
where
|
||||
columnIsUpdatable = _cmIsUpdatable (pgiMutability columnInfo)
|
||||
columnIsPermitted = Set.member (pgiColumn columnInfo) (upiCols permissions)
|
||||
columnHasNoPreset = not (Map.member (pgiColumn columnInfo) (upiSet permissions))
|
||||
columnIsUpdatable = _cmIsUpdatable (ciMutability columnInfo)
|
||||
columnIsPermitted = Set.member (ciColumn columnInfo) (upiCols permissions)
|
||||
columnHasNoPreset = not (Map.member (ciColumn columnInfo) (upiSet permissions))
|
||||
|
@ -180,12 +180,12 @@ updateOperator ::
|
||||
updateOperator tableGQLName opName mkParser columns opDesc objDesc = do
|
||||
fieldParsers :: NonEmpty (P.InputFieldsParser n (Maybe (Column b, a))) <-
|
||||
for columns \columnInfo -> do
|
||||
let fieldName = pgiName columnInfo
|
||||
fieldDesc = pgiDescription columnInfo
|
||||
let fieldName = ciName columnInfo
|
||||
fieldDesc = ciDescription columnInfo
|
||||
fieldParser <- mkParser columnInfo
|
||||
pure $
|
||||
P.fieldOptional fieldName fieldDesc fieldParser
|
||||
`mapField` \value -> (pgiColumn columnInfo, value)
|
||||
`mapField` \value -> (ciColumn columnInfo, value)
|
||||
|
||||
objName <- P.mkTypename $ tableGQLName <> opName <> $$(litName "_input")
|
||||
|
||||
@ -213,8 +213,8 @@ setOp = UpdateOperator {..}
|
||||
let typedParser columnInfo =
|
||||
fmap P.mkParameter
|
||||
<$> columnParser
|
||||
(pgiType columnInfo)
|
||||
(Nullability $ pgiIsNullable columnInfo)
|
||||
(ciType columnInfo)
|
||||
(Nullability $ ciIsNullable columnInfo)
|
||||
|
||||
updateOperator
|
||||
tableGQLName
|
||||
@ -242,8 +242,8 @@ incOp = UpdateOperator {..}
|
||||
let typedParser columnInfo =
|
||||
fmap P.mkParameter
|
||||
<$> columnParser
|
||||
(pgiType columnInfo)
|
||||
(Nullability $ pgiIsNullable columnInfo)
|
||||
(ciType columnInfo)
|
||||
(Nullability $ ciIsNullable columnInfo)
|
||||
|
||||
updateOperator
|
||||
tableGQLName
|
||||
|
@ -215,7 +215,7 @@ buildInsPermInfo source tn fieldInfoMap (PermDef _rn (InsPerm checkCond set mCol
|
||||
_ <- askColumnType fieldInfoMap col relInInsErr
|
||||
-- Check that the column is insertable
|
||||
ci <- askColInfo fieldInfoMap col ""
|
||||
unless (_cmIsInsertable $ pgiMutability ci) $
|
||||
unless (_cmIsInsertable $ ciMutability ci) $
|
||||
throw500
|
||||
( "Column " <> col
|
||||
<<> " is not insertable and so cannot have insert permissions defined"
|
||||
@ -230,7 +230,7 @@ buildInsPermInfo source tn fieldInfoMap (PermDef _rn (InsPerm checkCond set mCol
|
||||
return (InsPermInfo (HS.fromList insColsWithoutPresets) be setColsSQL backendOnly reqHdrs, deps)
|
||||
where
|
||||
backendOnly = Just True == mBackendOnly
|
||||
allCols = map pgiColumn $ getCols fieldInfoMap
|
||||
allCols = map ciColumn $ getCols fieldInfoMap
|
||||
insCols = maybe allCols (convColSpec fieldInfoMap) mCols
|
||||
relInInsErr = "Only table columns can have insert permissions defined, not relationships or other field types"
|
||||
|
||||
@ -332,7 +332,7 @@ buildUpdPermInfo source tn fieldInfoMap (UpdPerm colSpec set fltr check) = do
|
||||
_ <- askColumnType fieldInfoMap updCol relInUpdErr
|
||||
-- Check that the column is updatable
|
||||
ci <- askColInfo fieldInfoMap updCol ""
|
||||
unless (_cmIsUpdatable $ pgiMutability ci) $
|
||||
unless (_cmIsUpdatable $ ciMutability ci) $
|
||||
throw500
|
||||
( "Column " <> updCol
|
||||
<<> " is not updatable and so cannot have update permissions defined"
|
||||
|
@ -25,7 +25,7 @@ import Hasura.Session
|
||||
|
||||
convColSpec :: FieldInfoMap (FieldInfo b) -> PermColSpec b -> [Column b]
|
||||
convColSpec _ (PCCols cols) = cols
|
||||
convColSpec cim PCStar = map pgiColumn $ getCols cim
|
||||
convColSpec cim PCStar = map ciColumn $ getCols cim
|
||||
|
||||
permissionIsDefined ::
|
||||
Maybe (RolePermInfo backend) -> PermAccessor backend a -> Bool
|
||||
|
@ -225,10 +225,10 @@ buildRemoteFieldInfo lhsIdentifier lhsJoinFields RemoteRelationship {..} allSour
|
||||
tgtField <- askFieldInfo targetColumns tgtFieldName
|
||||
pure (srcFieldName, lhsJoinField, tgtField)
|
||||
mapping <- for columnPairs \(srcFieldName, srcColumn, tgtColumn) -> do
|
||||
tgtScalar <- case pgiType tgtColumn of
|
||||
tgtScalar <- case ciType tgtColumn of
|
||||
ColumnScalar scalarType -> pure scalarType
|
||||
ColumnEnumReference _ -> throw400 NotSupported "relationships to enum fields are not supported yet"
|
||||
pure (srcFieldName, (srcColumn, tgtScalar, pgiColumn tgtColumn))
|
||||
pure (srcFieldName, (srcColumn, tgtScalar, ciColumn tgtColumn))
|
||||
let sourceConfig = _rsConfig targetSourceInfo
|
||||
sourceCustomization = _rsCustomization targetSourceInfo
|
||||
rsri =
|
||||
@ -239,7 +239,7 @@ buildRemoteFieldInfo lhsIdentifier lhsJoinFields RemoteRelationship {..} allSour
|
||||
flip map columnPairs \(_, _srcColumn, tgtColumn) ->
|
||||
SchemaDependency
|
||||
( SOSourceObj _tsrdSource $
|
||||
AB.mkAnyBackend $ SOITableObj @b' targetTable $ TOCol @b' $ pgiColumn tgtColumn
|
||||
AB.mkAnyBackend $ SOITableObj @b' targetTable $ TOCol @b' $ ciColumn tgtColumn
|
||||
)
|
||||
DRRemoteRelationship
|
||||
requiredLHSJoinFields = fmap (\(srcField, _, _) -> srcField) $ Map.fromList mapping
|
||||
|
@ -82,7 +82,7 @@ addNonColumnFields =
|
||||
-- 1. all columns
|
||||
-- 2. computed fields which don't expect arguments other than the table row and user session
|
||||
let lhsJoinFields =
|
||||
let columnFields = columns <&> \columnInfo -> JoinColumn (pgiColumn columnInfo) (pgiType columnInfo)
|
||||
let columnFields = columns <&> \columnInfo -> JoinColumn (ciColumn columnInfo) (ciType columnInfo)
|
||||
computedFields = M.fromList $
|
||||
flip mapMaybe (M.toList computedFieldInfos) $
|
||||
\(cfName, (ComputedFieldInfo {..}, _)) -> do
|
||||
@ -146,7 +146,7 @@ addNonColumnFields =
|
||||
returnA -< Nothing
|
||||
|
||||
noCustomFieldConflicts = proc (columns, nonColumnFields) -> do
|
||||
let columnsByGQLName = mapFromL pgiName $ M.elems columns
|
||||
let columnsByGQLName = mapFromL ciName $ M.elems columns
|
||||
(|
|
||||
Inc.keyed
|
||||
( \_ (fieldInfo, metadata) ->
|
||||
@ -160,12 +160,12 @@ addNonColumnFields =
|
||||
-- If they are the same, `noColumnConflicts` will catch it, and it will produce a
|
||||
-- more useful error message.
|
||||
Just columnInfo
|
||||
| toTxt (pgiColumn columnInfo) /= G.unName fieldGQLName ->
|
||||
| toTxt (ciColumn columnInfo) /= G.unName fieldGQLName ->
|
||||
throwA
|
||||
-<
|
||||
err400 AlreadyExists $
|
||||
"field definition conflicts with custom field name for postgres column "
|
||||
<>> pgiColumn columnInfo
|
||||
<>> ciColumn columnInfo
|
||||
_ -> returnA -< ()
|
||||
)
|
||||
|) (fieldInfoGraphQLNames fieldInfo)
|
||||
|
@ -113,8 +113,8 @@ getTableDiff oldtm newtm =
|
||||
|
||||
mNewDesc = _ptmiDescription $ tmInfo newtm
|
||||
|
||||
droppedCols = map prciName $ getDifferenceOn prciPosition oldCols newCols
|
||||
existingCols = getOverlapWith prciPosition oldCols newCols
|
||||
droppedCols = map rciName $ getDifferenceOn rciPosition oldCols newCols
|
||||
existingCols = getOverlapWith rciPosition oldCols newCols
|
||||
alteredCols = filter (uncurry (/=)) existingCols
|
||||
|
||||
-- foreign keys are considered dropped only if their oid
|
||||
@ -375,8 +375,8 @@ alterColumnsInMetadata ::
|
||||
m ()
|
||||
alterColumnsInMetadata source alteredCols fields sc tn =
|
||||
for_ alteredCols $
|
||||
\( RawColumnInfo {prciName = oldName, prciType = oldType},
|
||||
RawColumnInfo {prciName = newName, prciType = newType}
|
||||
\( RawColumnInfo {rciName = oldName, rciType = oldType},
|
||||
RawColumnInfo {rciName = newName, rciType = newType}
|
||||
) -> do
|
||||
if
|
||||
| oldName /= newName ->
|
||||
|
@ -462,7 +462,7 @@ buildTableCache = Inc.cache proc (source, sourceConfig, dbTablesMeta, tableBuild
|
||||
|) maybeInfo
|
||||
|
||||
let columns :: [RawColumnInfo b] = _ptmiColumns metadataTable
|
||||
columnMap = mapFromL (FieldName . toTxt . prciName) columns
|
||||
columnMap = mapFromL (FieldName . toTxt . rciName) columns
|
||||
primaryKey = _ptmiPrimaryKey metadataTable
|
||||
rawPrimaryKey <- liftEitherA -< traverse (resolvePrimaryKeyColumns columnMap) primaryKey
|
||||
enumValues <-
|
||||
@ -550,36 +550,36 @@ buildTableCache = Inc.cache proc (source, sourceConfig, dbTablesMeta, tableBuild
|
||||
resolvedType <- resolveColumnType
|
||||
pure
|
||||
ColumnInfo
|
||||
{ pgiColumn = pgCol,
|
||||
pgiName = name,
|
||||
pgiPosition = prciPosition rawInfo,
|
||||
pgiType = resolvedType,
|
||||
pgiIsNullable = prciIsNullable rawInfo,
|
||||
pgiDescription = prciDescription rawInfo,
|
||||
pgiMutability = prciMutability rawInfo
|
||||
{ ciColumn = pgCol,
|
||||
ciName = name,
|
||||
ciPosition = rciPosition rawInfo,
|
||||
ciType = resolvedType,
|
||||
ciIsNullable = rciIsNullable rawInfo,
|
||||
ciDescription = rciDescription rawInfo,
|
||||
ciMutability = rciMutability rawInfo
|
||||
}
|
||||
where
|
||||
pgCol = prciName rawInfo
|
||||
pgCol = rciName rawInfo
|
||||
resolveColumnType =
|
||||
case Map.lookup pgCol tableEnumReferences of
|
||||
-- no references? not an enum
|
||||
Nothing -> pure $ ColumnScalar (prciType rawInfo)
|
||||
Nothing -> pure $ ColumnScalar (rciType rawInfo)
|
||||
-- one reference? is an enum
|
||||
Just (enumReference :| []) -> pure $ ColumnEnumReference enumReference
|
||||
-- multiple referenced enums? the schema is strange, so let’s reject it
|
||||
Just enumReferences ->
|
||||
throw400 ConstraintViolation $
|
||||
"column " <> prciName rawInfo <<> " in table " <> tableName
|
||||
"column " <> rciName rawInfo <<> " in table " <> tableName
|
||||
<<> " references multiple enum tables ("
|
||||
<> commaSeparated (map (dquote . erTable) $ toList enumReferences)
|
||||
<> ")"
|
||||
|
||||
assertNoDuplicateFieldNames columns =
|
||||
void $ flip Map.traverseWithKey (Map.groupOn pgiName columns) \name columnsWithName ->
|
||||
void $ flip Map.traverseWithKey (Map.groupOn ciName columns) \name columnsWithName ->
|
||||
case columnsWithName of
|
||||
one : two : more ->
|
||||
throw400 AlreadyExists $
|
||||
"the definitions of columns "
|
||||
<> englishList "and" (dquote . pgiColumn <$> (one :| two : more))
|
||||
<> englishList "and" (dquote . ciColumn <$> (one :| two : more))
|
||||
<> " are in conflict: they are mapped to the same field name, " <>> name
|
||||
_ -> pure ()
|
||||
|
@ -172,7 +172,7 @@ convInsertQuery objsParser sessVarBldr prepFn (InsertQuery tableName _ val oC mR
|
||||
|
||||
let mutOutput = mkDefaultMutFlds mAnnRetCols
|
||||
|
||||
let defInsVals = HM.fromList [(column, S.columnDefaultValue) | column <- pgiColumn <$> getCols fieldInfoMap]
|
||||
let defInsVals = HM.fromList [(column, S.columnDefaultValue) | column <- ciColumn <$> getCols fieldInfoMap]
|
||||
allCols = getCols fieldInfoMap
|
||||
insCols = HM.keys defInsVals
|
||||
|
||||
|
@ -74,7 +74,7 @@ mkAdminRolePermInfo ti =
|
||||
RolePermInfo (Just i) (Just s) (Just u) (Just d)
|
||||
where
|
||||
fields = _tciFieldInfoMap ti
|
||||
pgCols = map pgiColumn $ getCols fields
|
||||
pgCols = map ciColumn $ getCols fields
|
||||
pgColsWithFilter = M.fromList $ map (,Nothing) pgCols
|
||||
scalarComputedFields =
|
||||
HS.fromList $ map _cfiName $ onlyScalarComputedFields $ getComputedFieldInfos fields
|
||||
@ -282,7 +282,7 @@ checkOnColExp ::
|
||||
m (AnnBoolExpFldSQL b)
|
||||
checkOnColExp spi sessVarBldr annFld = case annFld of
|
||||
AVColumn colInfo _ -> do
|
||||
let cn = pgiColumn colInfo
|
||||
let cn = ciColumn colInfo
|
||||
checkSelOnCol spi cn
|
||||
return annFld
|
||||
AVRelationship relInfo nesAnn -> do
|
||||
|
@ -68,7 +68,7 @@ convWildcard fieldInfoMap selPermInfo wildcard =
|
||||
(StarDot wc) -> (simpleCols ++) <$> (catMaybes <$> relExtCols wc)
|
||||
where
|
||||
cols = spiCols selPermInfo
|
||||
pgCols = map pgiColumn $ getCols fieldInfoMap
|
||||
pgCols = map ciColumn $ getCols fieldInfoMap
|
||||
relColInfos = getRels fieldInfoMap
|
||||
|
||||
simpleCols = map ECSimple $ filter (`HM.member` cols) pgCols
|
||||
@ -125,8 +125,8 @@ convOrderByElem sessVarBldr (flds, spi) = \case
|
||||
fldInfo <- askFieldInfo flds fldName
|
||||
case fldInfo of
|
||||
FIColumn colInfo -> do
|
||||
checkSelOnCol spi (pgiColumn colInfo)
|
||||
let ty = pgiType colInfo
|
||||
checkSelOnCol spi (ciColumn colInfo)
|
||||
let ty = ciType colInfo
|
||||
if isScalarColumnWhere isGeoType ty
|
||||
then
|
||||
throw400 UnexpectedPayload $
|
||||
@ -203,7 +203,7 @@ convSelectQ table fieldInfoMap selPermInfo selQ sessVarBldr prepValBldr = do
|
||||
(colInfo, caseBoolExpMaybe) <- convExtSimple fieldInfoMap selPermInfo pgCol
|
||||
resolvedCaseBoolExp <-
|
||||
traverse (convAnnColumnCaseBoolExpPartialSQL sessVarBldr) caseBoolExpMaybe
|
||||
pure (fromCol @('Postgres 'Vanilla) pgCol, mkAnnColumnField (pgiColumn colInfo) (pgiType colInfo) resolvedCaseBoolExp Nothing)
|
||||
pure (fromCol @('Postgres 'Vanilla) pgCol, mkAnnColumnField (ciColumn colInfo) (ciType colInfo) resolvedCaseBoolExp Nothing)
|
||||
(ECRel relName mAlias relSelQ) -> do
|
||||
annRel <-
|
||||
convExtRel
|
||||
|
@ -429,7 +429,7 @@ instance (Backend b, Hashable (BooleanOperators b a), Hashable a) => Hashable (A
|
||||
instance (Backend b, ToJSONKeyValue (BooleanOperators b a), ToJSON a) => ToJSONKeyValue (AnnBoolExpFld b a) where
|
||||
toJSONKeyValue = \case
|
||||
AVColumn pci opExps ->
|
||||
( toTxt $ pgiColumn pci,
|
||||
( toTxt $ ciColumn pci,
|
||||
toJSON (pci, object . pure . toJSONKeyValue <$> opExps)
|
||||
)
|
||||
AVRelationship ri relBoolExp ->
|
||||
|
@ -463,7 +463,7 @@ mkAnnColumnFieldAsText ::
|
||||
ColumnInfo backend ->
|
||||
AnnFieldG backend r v
|
||||
mkAnnColumnFieldAsText ci =
|
||||
AFColumn (AnnColumnField (pgiColumn ci) (pgiType ci) True Nothing Nothing)
|
||||
AFColumn (AnnColumnField (ciColumn ci) (ciType ci) True Nothing Nothing)
|
||||
|
||||
-- Aggregation fields
|
||||
|
||||
|
@ -165,15 +165,15 @@ parseScalarValuesColumnType columnType =
|
||||
-- containing a 'PGColumnType', it only contains a 'PGScalarType', which is combined with the
|
||||
-- 'pcirReferences' field and other table data to eventually resolve the type to a 'PGColumnType'.
|
||||
data RawColumnInfo (b :: BackendType) = RawColumnInfo
|
||||
{ prciName :: !(Column b),
|
||||
{ rciName :: !(Column b),
|
||||
-- | The “ordinal position” of the column according to Postgres. Numbering starts at 1 and
|
||||
-- increases. Dropping a column does /not/ cause the columns to be renumbered, so a column can be
|
||||
-- consistently identified by its position.
|
||||
prciPosition :: !Int,
|
||||
prciType :: !(ScalarType b),
|
||||
prciIsNullable :: !Bool,
|
||||
prciDescription :: !(Maybe G.Description),
|
||||
prciMutability :: ColumnMutability
|
||||
rciPosition :: !Int,
|
||||
rciType :: !(ScalarType b),
|
||||
rciIsNullable :: !Bool,
|
||||
rciDescription :: !(Maybe G.Description),
|
||||
rciMutability :: ColumnMutability
|
||||
}
|
||||
deriving (Generic)
|
||||
|
||||
@ -223,14 +223,14 @@ instance ToJSON ColumnMutability where
|
||||
-- | “Resolved” column info, produced from a 'RawColumnInfo' value that has been combined with
|
||||
-- other schema information to produce a 'PGColumnType'.
|
||||
data ColumnInfo (b :: BackendType) = ColumnInfo
|
||||
{ pgiColumn :: !(Column b),
|
||||
{ ciColumn :: !(Column b),
|
||||
-- | field name exposed in GraphQL interface
|
||||
pgiName :: !G.Name,
|
||||
pgiPosition :: !Int,
|
||||
pgiType :: !(ColumnType b),
|
||||
pgiIsNullable :: !Bool,
|
||||
pgiDescription :: !(Maybe G.Description),
|
||||
pgiMutability :: ColumnMutability
|
||||
ciName :: !G.Name,
|
||||
ciPosition :: !Int,
|
||||
ciType :: !(ColumnType b),
|
||||
ciIsNullable :: !Bool,
|
||||
ciDescription :: !(Maybe G.Description),
|
||||
ciMutability :: ColumnMutability
|
||||
}
|
||||
deriving (Generic)
|
||||
|
||||
@ -254,14 +254,14 @@ onlyNumCols :: forall b. Backend b => [ColumnInfo b] -> [ColumnInfo b]
|
||||
onlyNumCols = filter isNumCol
|
||||
|
||||
isNumCol :: forall b. Backend b => ColumnInfo b -> Bool
|
||||
isNumCol = isScalarColumnWhere (isNumType @b) . pgiType
|
||||
isNumCol = isScalarColumnWhere (isNumType @b) . ciType
|
||||
|
||||
onlyComparableCols :: forall b. Backend b => [ColumnInfo b] -> [ColumnInfo b]
|
||||
onlyComparableCols = filter (isScalarColumnWhere (isComparableType @b) . pgiType)
|
||||
onlyComparableCols = filter (isScalarColumnWhere (isComparableType @b) . ciType)
|
||||
|
||||
getColInfos :: Backend b => [Column b] -> [ColumnInfo b] -> [ColumnInfo b]
|
||||
getColInfos cols allColInfos =
|
||||
flip filter allColInfos $ \ci -> pgiColumn ci `elem` cols
|
||||
flip filter allColInfos $ \ci -> ciColumn ci `elem` cols
|
||||
|
||||
fromCol :: Backend b => Column b -> FieldName
|
||||
fromCol = FieldName . toTxt
|
||||
@ -277,13 +277,13 @@ data ColumnReference (b :: BackendType)
|
||||
|
||||
columnReferenceType :: ColumnReference backend -> ColumnType backend
|
||||
columnReferenceType = \case
|
||||
ColumnReferenceColumn column -> pgiType column
|
||||
ColumnReferenceColumn column -> ciType column
|
||||
ColumnReferenceComputedField _ scalarType -> ColumnScalar scalarType
|
||||
ColumnReferenceCast _ targetType -> targetType
|
||||
|
||||
instance Backend b => ToTxt (ColumnReference b) where
|
||||
toTxt = \case
|
||||
ColumnReferenceColumn column -> toTxt $ pgiColumn column
|
||||
ColumnReferenceColumn column -> toTxt $ ciColumn column
|
||||
ColumnReferenceComputedField name _ -> toTxt name
|
||||
ColumnReferenceCast reference targetType ->
|
||||
toTxt reference <> "::" <> toTxt targetType
|
||||
|
@ -76,7 +76,6 @@ module Hasura.RQL.Types.SchemaCache
|
||||
getCols,
|
||||
getRels,
|
||||
getComputedFieldInfos,
|
||||
isPGColInfo,
|
||||
RelInfo (..),
|
||||
PermAccessor (..),
|
||||
permAccToLens,
|
||||
@ -559,7 +558,7 @@ getColExpDeps bexp = do
|
||||
BoolExpCtx {source, currTable} <- ask
|
||||
case bexp of
|
||||
AVColumn colInfo opExps ->
|
||||
let columnName = pgiColumn colInfo
|
||||
let columnName = ciColumn colInfo
|
||||
colDepReason = bool DRSessionVariable DROnType $ any hasStaticExp opExps
|
||||
colDep = mkColDep @b colDepReason source currTable columnName
|
||||
in (colDep :) <$> mkOpExpDeps opExps
|
||||
|
@ -42,7 +42,6 @@ module Hasura.RQL.Types.Table
|
||||
getRels,
|
||||
getRemoteFieldInfoName,
|
||||
isMutable,
|
||||
isPGColInfo,
|
||||
permAccToLens,
|
||||
permAccToType,
|
||||
permDel,
|
||||
@ -213,14 +212,14 @@ type FieldInfoMap = M.HashMap FieldName
|
||||
|
||||
fieldInfoName :: forall b. Backend b => FieldInfo b -> FieldName
|
||||
fieldInfoName = \case
|
||||
FIColumn info -> fromCol @b $ pgiColumn info
|
||||
FIColumn info -> fromCol @b $ ciColumn info
|
||||
FIRelationship info -> fromRel $ riName info
|
||||
FIComputedField info -> fromComputedField $ _cfiName info
|
||||
FIRemoteRelationship info -> fromRemoteRelationship $ getRemoteFieldInfoName info
|
||||
|
||||
fieldInfoGraphQLName :: FieldInfo b -> Maybe G.Name
|
||||
fieldInfoGraphQLName = \case
|
||||
FIColumn info -> Just $ pgiName info
|
||||
FIColumn info -> Just $ ciName info
|
||||
FIRelationship info -> G.mkName $ relNameToTxt $ riName info
|
||||
FIComputedField info -> G.mkName $ computedFieldNameToText $ _cfiName info
|
||||
FIRemoteRelationship info -> G.mkName $ relNameToTxt $ getRemoteFieldInfoName info
|
||||
@ -249,7 +248,7 @@ getCols = mapMaybe (^? _FIColumn) . M.elems
|
||||
|
||||
-- | Sort columns based on their ordinal position
|
||||
sortCols :: [ColumnInfo backend] -> [ColumnInfo backend]
|
||||
sortCols = sortBy (\l r -> compare (pgiPosition l) (pgiPosition r))
|
||||
sortCols = sortBy (\l r -> compare (ciPosition l) (ciPosition r))
|
||||
|
||||
getRels :: FieldInfoMap (FieldInfo backend) -> [RelInfo backend]
|
||||
getRels = mapMaybe (^? _FIRelationship) . M.elems
|
||||
@ -257,10 +256,6 @@ getRels = mapMaybe (^? _FIRelationship) . M.elems
|
||||
getComputedFieldInfos :: FieldInfoMap (FieldInfo backend) -> [ComputedFieldInfo backend]
|
||||
getComputedFieldInfos = mapMaybe (^? _FIComputedField) . M.elems
|
||||
|
||||
isPGColInfo :: FieldInfo backend -> Bool
|
||||
isPGColInfo (FIColumn _) = True
|
||||
isPGColInfo _ = False
|
||||
|
||||
data InsPermInfo (b :: BackendType) = InsPermInfo
|
||||
{ ipiCols :: !(HS.HashSet (Column b)),
|
||||
ipiCheck :: !(AnnBoolExpPartialSQL b),
|
||||
@ -842,7 +837,7 @@ askColumnType ::
|
||||
Text ->
|
||||
m (ColumnType backend)
|
||||
askColumnType m c msg =
|
||||
pgiType <$> askColInfo m c msg
|
||||
ciType <$> askColInfo m c msg
|
||||
|
||||
askColInfo ::
|
||||
forall m backend.
|
||||
|
Loading…
Reference in New Issue
Block a user