Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addMetaColumns(sql) {
const parsed = parser.parse(sql);
const tree = parsed.query;
if(!tree.length) {
return Promise.reject(parsed.error);
}
// Ensure that the necessary database objects have been created
return this.ensureObjects(tree).then(() => {
// Add the uid and rev columns to the parse tree
this._addMetaColumns(tree);
// Deparse the parse tree back into a query
return {
sql : parser.deparse(tree),
tables : this.getTables(tree)
};
return this.ensureObjects(tree).then(() => {
// Add the uid and rev columns to the parse tree
this._addMetaColumns(tree);
// Deparse the parse tree back into a query
return {
sql : parser.deparse(tree),
tables : this.getTables(tree)
};
});
}
export function parsePostgresQuery(
queryString: string,
sourceFile: SourceFile,
sourceMap: QuerySourceMapSpan[],
spreadTypes: ExpressionSpreadTypes
): Query {
const context: QueryContext = {
expressionSpreadTypes: spreadTypes,
query: queryString,
sourceFile,
sourceMap
}
const result = QueryParser.parse(queryString)
if (result.error) {
const fakePath = createQueryNodePath({ SelectStmt: { op: 0 } }, [], "")
const query = instantiateQuery(fakePath, context)
const error = new Error(`Syntax error in SQL query.\nSubstituted query: ${queryString.trim()}`)
throw augmentFileValidationError(augmentQuerySyntaxError(error, result.error, query), query)
}
const parsedQuery = result.query[0]
const queryPath = createQueryNodePath(parsedQuery, [], "")
return instantiateQuery(queryPath, context)
}