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

Function parsePostgresQuery

src/postgres/parse-pg-query.ts:209–234  ·  view source on GitHub ↗
(
  queryString: string,
  sourceFile: SourceFile,
  sourceMap: QuerySourceMapSpan[],
  spreadTypes: ExpressionSpreadTypes
)

Source from the content-addressed store, hash-verified

207}
208
209export function parsePostgresQuery(
210 queryString: string,
211 sourceFile: SourceFile,
212 sourceMap: QuerySourceMapSpan[],
213 spreadTypes: ExpressionSpreadTypes
214): Query {
215 const context: QueryContext = {
216 expressionSpreadTypes: spreadTypes,
217 query: queryString,
218 sourceFile,
219 sourceMap
220 }
221 const result = QueryParser.parse(queryString)
222
223 if (result.error) {
224 const fakePath = createQueryNodePath({ SelectStmt: { op: 0 } }, [], "")
225 const query = instantiateQuery(fakePath, context)
226 const error = new Error(`Syntax error in SQL query.\nSubstituted query: ${queryString.trim()}`)
227 throw augmentFileValidationError(augmentQuerySyntaxError(error, result.error, query), query)
228 }
229
230 const parsedQuery = result.query[0]
231 const queryPath = createQueryNodePath(parsedQuery, [], "")
232
233 return instantiateQuery(queryPath, context)
234}

Callers 1

parseQueryFunction · 0.90

Calls 4

createQueryNodePathFunction · 0.90
augmentQuerySyntaxErrorFunction · 0.90
instantiateQueryFunction · 0.85

Tested by

no test coverage detected