( statement: QueryNodePath<QueryParser.Query>, spreadTypes: ExpressionSpreadTypes )
| 97 | } |
| 98 | |
| 99 | function getReferencedColumns( |
| 100 | statement: QueryNodePath<QueryParser.Query>, |
| 101 | spreadTypes: ExpressionSpreadTypes |
| 102 | ): ColumnReference[] { |
| 103 | const referencedColumns: ColumnReference[] = [] |
| 104 | |
| 105 | traverseSubTree(statement, (path, $cancelRecursion) => { |
| 106 | const spreadType = isParamRef(path.node) ? spreadTypes[path.node.ParamRef.number] : null |
| 107 | |
| 108 | if (path.node === statement.node) return |
| 109 | if (isSubquery(path.node)) return $cancelRecursion |
| 110 | |
| 111 | if (isColumnRef(path.node)) { |
| 112 | const relationRefs = getTableReferences(statement, false) |
| 113 | const columnRef = resolveColumnReference(path, relationRefs) |
| 114 | |
| 115 | if (columnRef && columnRef.columnName !== placeholderColumnName) { |
| 116 | referencedColumns.push(columnRef) |
| 117 | } |
| 118 | } else if (isResTarget(path.node) && path.node.ResTarget.name) { |
| 119 | const relationRefs = getTableReferences(statement, false) |
| 120 | const columnRef = resolveResTarget(path, relationRefs) |
| 121 | |
| 122 | if (columnRef && columnRef.columnName !== placeholderColumnName) { |
| 123 | referencedColumns.push(columnRef) |
| 124 | } |
| 125 | } else if (spreadType) { |
| 126 | const relationRefs = getTableReferences(statement, false) |
| 127 | |
| 128 | const tableRefsInScope: TableReference[] = relationRefs.map(ref => ({ |
| 129 | as: ref.node.RangeVar.alias ? ref.node.RangeVar.alias.Alias.aliasname : undefined, |
| 130 | tableName: ref.node.RangeVar.relname, |
| 131 | path |
| 132 | })) |
| 133 | |
| 134 | for (const spreadArgKey of Object.keys(spreadType)) { |
| 135 | referencedColumns.push({ |
| 136 | tableRefsInScope: filterDuplicateTableRefs(tableRefsInScope), |
| 137 | columnName: spreadArgKey, |
| 138 | path |
| 139 | }) |
| 140 | } |
| 141 | |
| 142 | if (spreadType === spreadTypeAny || !spreadType) { |
| 143 | referencedColumns.push({ |
| 144 | any: true, |
| 145 | tableRefsInScope: filterDuplicateTableRefs(tableRefsInScope), |
| 146 | columnName: "", |
| 147 | path |
| 148 | }) |
| 149 | } |
| 150 | } |
| 151 | }) |
| 152 | return referencedColumns |
| 153 | } |
| 154 | |
| 155 | function getReturningColumns(statement: QueryNodePath<QueryParser.Query>): ColumnReference[] { |
| 156 | const body = (statement.node as any)[statement.type] |
no test coverage detected