Registry / database / sql-surveyor

sql-surveyor

JSON →
library1.4.1jsnpmunverified

High-level SQL parser that extracts tables, columns, aliases, and more from SQL scripts into an easy-to-consume object. Currently at version 1.4.1, actively maintained on GitHub with regular releases. Supports PostgreSQL, MySQL, SQL Server, and Oracle dialects (PL/pgSQL, T-SQL, PL/SQL). Unlike low-level parsers that return parse trees, SQL Surveyor provides a structured object with output columns, referenced columns, referenced tables, and tokens, making analysis straightforward. Includes TypeScript type definitions. Zero configuration required.

npm install sql-surveyor
INSTALL
IMPORT
SIG · SQL-SURVEYOR
S
sql-surveyor
databasejavascriptv1.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SQLSurveyor
import { SQLSurveyor } from 'sql-surveyor';
import SQLSurveyor from 'sql-surveyor';
Use named import, not default. The library exports ES modules.
SQLDialect
import { SQLDialect } from 'sql-surveyor';
import { Dialect } from 'sql-surveyor';
The enum is named SQLDialect, not Dialect.
ParsedSql type
import type { ParsedSql } from 'sql-surveyor';
If using TypeScript, import types for ParsedSql, ParsedQuery, etc. via type import.

Demonstrates basic usage: import, instantiate with dialect, parse a SQL query, and access the first parsed query.

import { SQLSurveyor, SQLDialect } from 'sql-surveyor'; const sql = 'SELECT t1.columnA, t2.columnB FROM table1 t1 JOIN table2 t2 ON t1.id = t2.table1_id'; const surveyor = new SQLSurveyor(SQLDialect.PLSQL); const parsedSql = surveyor.survey(sql); console.log(parsedSql.parsedQueries['0']);
Debug
Known issues
gotchaNot all SQL features are supported; complex queries with CTEs, window functions, or subqueries may produce incomplete output.
fix
Check the documentation for known limitations. For unsupported features, consider using a lower-level parser like node-sql-parser.
affects: <=1.4.1
gotchaThe library is case-sensitive for table and column names when comparing in output.
fix
Ensure your SQL identifiers are consistently cased in the input.
affects: >=1.0.0
gotchaToken positions use lineStart/lineEnd starting at 1, but startIndex/stopIndex are 0-based indices relative to the entire input string.
fix
When using token locations, remember that line numbers start at 1, while character indices start at 0.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'sql-surveyor' or its corresponding type declarations.
Package not installed or TypeScript cannot find its types.
fix
Run 'npm install sql-surveyor'. If using TypeScript, ensure 'node_modules/@types' is in typeRoots or the package ships types (it does).
Uncaught TypeError: SQLSurveyor is not a constructor
Default import used instead of named import.
fix
Change import to 'import { SQLSurveyor } from 'sql-surveyor';'
Upgrade
Version history
1.4.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
Meta
2
OpenAI (training)
1
Resources
sql-surveyor — npm install sql-surveyor · libregistry