MCPcopy Create free account
hub / github.com/andywer/postguard / instantiateQuery

Function instantiateQuery

src/postgres/parse-pg-query.ts:174–207  ·  view source on GitHub ↗
(path: QueryNodePath<QueryParser.Query>, context: QueryContext)

Source from the content-addressed store, hash-verified

172}
173
174function 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
209export function parsePostgresQuery(
210 queryString: string,

Callers 1

parsePostgresQueryFunction · 0.85

Calls 8

getNodeTypeFunction · 0.90
getQueryPathParentFunction · 0.90
isCommonTableExprFunction · 0.90
getReferencedColumnsFunction · 0.85
getTableReferencesFunction · 0.85
getReturningColumnsFunction · 0.85
getSubqueriesFunction · 0.85

Tested by

no test coverage detected