googlesql-parser
v2026.9.1
Published
GoogleSQL parser and analyzer for Node.js, ported from the official library
Readme
googlesql-parser
Node.js (WASM) wrapper around googlesql.
const { load } = require('googlesql-parser');
const googleSql = await load();
googleSql.validate('SELECT id FROM dataset.users');
// { ok: true }
googleSql.validate('SELECT id FROM');
// { ok: false, error: { message: 'Syntax error: Unexpected end of statement',
// line: 1, column: 15 } }
googleSql.statementKind('CREATE TABLE d.t AS SELECT 1 AS x');
// 'CREATE_TABLE_AS_SELECT'
googleSql.extractNames("SELECT * FROM a.t JOIN EXTERNAL_QUERY('c', 'SELECT 1') USING (id)");
// { tables: [['a', 't']], tvfs: [['EXTERNAL_QUERY']], graphs: [] }
googleSql.extractNames('SELECT * FROM GRAPH_TABLE(a.g MATCH (n) COLUMNS(n.id))');
// { tables: [], tvfs: [], graphs: [['a', 'g']] }
googleSql.statementProperties('CREATE TEMP TABLE t (id INT64)');
// { kind: 'CREATE_TABLE', category: 'DDL',
// isCreateTemporaryObject: true, hints: {} }
googleSql.extractFunctionNames('SELECT COUNT(*), a.my_udf(x) FROM a.t');
// [['a', 'my_udf'], ['count']]
googleSql.selectColumnExpressions('SELECT id, UPPER(name) AS shouty FROM a.t');
// ['id', 'UPPER(name)']
googleSql.ddlTargetTable('CREATE TABLE a.t (id INT64)');
// ['a', 't']
googleSql.extractNamesFromScript('DECLARE x INT64; SELECT * FROM a.t;');
// { tables: [['a', 't']], tvfs: [], graphs: [] }load() instantiates the module once; every method on the result is
synchronous. Instances are independent and share no state.
Only a subset of the C++ API is currently exposed. If there are methods you'd like exposed, feel free to open an issue or a pull request.
