How to use pg-query-parser - 3 common examples

To help you get started, we’ve selected a few pg-query-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nothingisdead / pg-live-query / pguids.js View on Github external
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)
			};
github nothingisdead / pg-live-query / pguids.js View on Github external
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)
			};
		});
	}
github andywer / postguard / src / postgres / parse-pg-query.ts View on Github external
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)
}

pg-query-parser

The real PostgreSQL query parser

BSD-3-Clause
Latest version published 3 years ago

Package Health Score

39 / 100
Full package analysis

Popular pg-query-parser functions