Skip to content

@lanexio/parser-grammar-sql

This page documents @lanexio/parser-grammar-sql, the SQL grammar package supporting PostgreSQL and SQLite dialects. This package is at version 0.0.1 — the API may change before the 1.0.0 stable release.

  • Version: Beta
  • Module name: parser-grammar-sql
  • Package: @lanexio/parser-grammar-sql
  • Import path: @lanexio/parser-grammar-sql
  • Layer: 2 (Grammar)
  • Runtime: Universal
  • Module format: ESM
  • Stability: Beta (v0.0.1)
  • Primary use case: Parse SQL statements into a flat AST.
  • You need to parse SQL statements (PostgreSQL and SQLite dialects) into a traversable AST.
  • You are evaluating the SQL grammar for pre-1.0 use cases.
BoundaryDescription
InputsUint8Array (source bytes)
OutputsLexTree (flat AST)
Side effectsNone
DeterminismYes
External dependencies@lanexio/parser-core
Never-throw guaranteeYes
Security surfaceNone (parse only, no output generation)
  1. Install the package.

    Terminal window
    pnpm add @lanexio/parser-grammar-sql
  2. Import the named export.

    import { parseSql } from '@lanexio/parser-grammar-sql';
RequirementRequiredLayerNotes
@lanexio/parser-coreYes1^1.0.0
import { parseSql } from '@lanexio/parser-grammar-sql';
const encoder = new TextEncoder();
const bytes = encoder.encode('SELECT id, name FROM users WHERE active = true');
const tree = parseSql(bytes);
console.log(tree.nodeCount);
ExportTypeDescription
parseSql(bytes: Uint8Array) => LexTreeParse SQL. Never throws.
SqlKindconst objectNumeric kind IDs for all SQL node types.
SqlFieldconst objectNumeric field IDs for SQL slots.
SQL_FIELD_NAMES_BY_IDreadonly string[]Field name lookup by numeric field ID.
SQL_KIND_NAMES_BY_IDreadonly Record<number, string>Kind-name lookup by numeric ID.
LANEXIO_PARSER_GRAMMAR_SQL_PACKAGE_NAME"@lanexio/parser-grammar-sql"Stable npm package name constant for the SQL grammar package.
sqlGrammarLanexioParserPureGrammarGrammar descriptor for use with parser-pure.
sqlRegistrationGrammarRegistrationRegistration for the unified grammar registry.

No options object. The function signature is parseSql(bytes: Uint8Array): LexTree. Options are reserved for future extension.

PropertyTypeDescription
rootLexNodeRoot node of the SQL statement.
nodeCountnumberTotal nodes in the tree.
sourceUint8ArrayOriginal parsed bytes.
TypePurposeNotes
SqlKindTypeUnion of all SqlKind valuesType-safe kind reference
SqlFieldTypeUnion of all SqlField valuesType-safe field reference

No configuration options. SQL dialect detection is automatic based on input syntax.

  • No direct accessibility surface. The SQL parser produces flat AST data structures.
ConcernStatus
Generated output semanticsNot applicable (query format)
ARIA attributes in serialized outputNot applicable
Semantic element round-tripNot applicable
  • parseSql never throws on any byte sequence.
ThreatMitigationStatus
Malformed input byte sequencePanic-free guarantee: all inputs accepted, errors produce LexError AST nodesImplemented
PackageRelationshipLayerNotes
@lanexio/parser-coreRequires1Provides LexTree, LexNode, LexCursor
@lanexio/parserConsumes6Unified entry point

This package is at v0.0.1 and is in active development. The API surface is minimal and may change significantly before the 1.0.0 stable release. The package is published to npm for early evaluation. Use with caution in production.

Planned additions for v1.0.0 include:

  • Extended DML (INSERT, UPDATE, DELETE) support
  • Additional dialect coverage (MySQL, PostgreSQL-specific features)
  • ParseSqlOptions for dialect selection
VersionDateStatusNotable changes
0.0.12026-05-29CurrentInitial beta release. Apache-2.0.
  • This is a beta release. No migration guarantees until v1.0.0.