Registry / database / sql-lexer

sql-lexer

JSON →
library0.2.2jsnpmunverified

An SQL lexer for JavaScript targeting standard SQL92, SQL2011, MySQL, and SQLite. Current stable version is 0.2.2. The library aims to produce tokens suitable for building parsers, syntax highlighters, and other SQL tooling. It is still early in development (pre-1.0), with Postgres support planned but not yet implemented. Differentiator: focuses on multiple SQL dialects (MySQL, SQLite) beyond standard SQL, intended as a base for higher-level tools like migration generators and schema translators. However, documentation and ecosystem are minimal, and the API may change significantly before a 1.0 release.

npm install sql-lexer
INSTALL
IMPORT
SIG · SQL-LEXER
S
sql-lexer
databasejavascriptv0.2.2
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.

default
import Lexer from 'sql-lexer'
const Lexer = require('sql-lexer').default
The package has a default export; CommonJS require works but may need .default in some bundlers.
SQL92Lexer
import { SQL92Lexer } from 'sql-lexer'
const SQL92Lexer = require('sql-lexer').SQL92Lexer
Named export for the SQL92 dialect lexer.
MySQLLexer
import { MySQLLexer } from 'sql-lexer'
Named export for MySQL dialect. Fully functional.

Demonstrates basic usage: tokenizing an SQL query using default export and SQL92 dialect lexer. Outputs token objects.

import Lexer, { SQL92Lexer } from 'sql-lexer'; const sql = 'SELECT * FROM users WHERE id = 1'; const lexer = new Lexer(sql); const tokens = lexer.tokenize(); console.log(tokens); // Using specific dialect: const sql92Lexer = new SQL92Lexer(sql); const sql92Tokens = sql92Lexer.tokenize(); console.log(sql92Tokens);
Debug
Known issues
breakingPre-1.0 version; API may change without notice.
fix
Pin to exact version and monitor releases for breaking changes.
affects: <1.0.0
gotchaLexer.tokenize() returns an array of token objects, not strings.
fix
Handle token objects: { type, value, start, end }.
affects: 0.0.1 - 0.2.2
gotchaPostgres dialect not yet implemented; using 'postgres' will throw or return empty.
fix
Use 'mysql' or 'sqlite' dialect, or wait for future release.
affects: 0.0.1 - 0.2.2
deprecatedNo deprecations known, but many features are incomplete (e.g., SQL2011).
fix
Check documentation before relying on advanced SQL features.
affects: 0.2.2
Errors
Common errors & fixes
TypeError: Lexer is not a constructor
Using CommonJS require without .default in a modern environment.
fix
Use `import Lexer from 'sql-lexer'` or `const Lexer = require('sql-lexer').default`.
Cannot find module 'sql-lexer'
Package not installed or not in node_modules.
fix
Run `npm install sql-lexer` or check your package.json.
Unhandled token: ...
SQL contains syntax not recognized by the chosen dialect/version.
fix
Verify SQL is valid for the dialect (e.g., MySQL vs SQL92) and upgrade to latest version.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Meta
2
OpenAI (training)
1
Resources
sql-lexer — npm install sql-lexer · libregistry