(path: QueryNodePath<QueryParser.Query>, context: QueryContext)
| 172 | } |
| 173 | |
| 174 | function instantiateQuery(path: QueryNodePath<QueryParser.Query>, context: QueryContext): Query { |
| 175 | const referencedColumns = getReferencedColumns(path, context.expressionSpreadTypes) |
| 176 | const referencedTables = getTableReferences(path, true).map(tableRef => ({ |
| 177 | tableName: tableRef.node.RangeVar.relname, |
| 178 | path: tableRef |
| 179 | })) |
| 180 | |
| 181 | const returnedColumns = getReturningColumns(path) |
| 182 | |
| 183 | const subqueries: Query[] = getSubqueries(path).map(subqueryPath => |
| 184 | instantiateQuery(subqueryPath, context) |
| 185 | ) |
| 186 | const type = getNodeType(path.node) |
| 187 | .replace(/Stmt$/, "") |
| 188 | .toUpperCase() |
| 189 | |
| 190 | const parent = getQueryPathParent(path) |
| 191 | const exposedAsTable = |
| 192 | parent && isCommonTableExpr(parent.node) ? parent.node.CommonTableExpr.ctename : undefined |
| 193 | |
| 194 | return { |
| 195 | type, |
| 196 | path, |
| 197 | exposedAsTable, |
| 198 | referencedColumns, |
| 199 | referencedTables, |
| 200 | returnedColumns, |
| 201 | returnsIntoParentQuery: isReturningIntoParentQuery(path), |
| 202 | query: context.query, |
| 203 | sourceFile: context.sourceFile, |
| 204 | sourceMap: context.sourceMap, |
| 205 | subqueries |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | export function parsePostgresQuery( |
| 210 | queryString: string, |
no test coverage detected