@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.
Layer contract
Section titled “Layer contract”When to use this module
Section titled “When to use this module”- 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.
Module boundary
Section titled “Module boundary”| Boundary | Description |
|---|---|
| Inputs | Uint8Array (source bytes) |
| Outputs | LexTree (flat AST) |
| Side effects | None |
| Determinism | Yes |
| External dependencies | @lanexio/parser-core |
| Never-throw guarantee | Yes |
| Security surface | None (parse only, no output generation) |
Installation
Section titled “Installation”-
Install the package.
Terminal window pnpm add @lanexio/parser-grammar-sqlTerminal window npm install @lanexio/parser-grammar-sqlTerminal window yarn add @lanexio/parser-grammar-sql -
Import the named export.
import { parseSql } from '@lanexio/parser-grammar-sql';
Peer dependencies
Section titled “Peer dependencies”| Requirement | Required | Layer | Notes |
|---|---|---|---|
@lanexio/parser-core | Yes | 1 | ^1.0.0 |
Basic Usage
Section titled “Basic Usage”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);Exports
Section titled “Exports”| Export | Type | Description |
|---|---|---|
parseSql | (bytes: Uint8Array) => LexTree | Parse SQL. Never throws. |
SqlKind | const object | Numeric kind IDs for all SQL node types. |
SqlField | const object | Numeric field IDs for SQL slots. |
SQL_FIELD_NAMES_BY_ID | readonly string[] | Field name lookup by numeric field ID. |
SQL_KIND_NAMES_BY_ID | readonly 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. |
sqlGrammar | LanexioParserPureGrammar | Grammar descriptor for use with parser-pure. |
sqlRegistration | GrammarRegistration | Registration for the unified grammar registry. |
Options
Section titled “Options”No options object. The function signature is parseSql(bytes: Uint8Array): LexTree. Options are reserved for future extension.
Return shape
Section titled “Return shape”| Property | Type | Description |
|---|---|---|
root | LexNode | Root node of the SQL statement. |
nodeCount | number | Total nodes in the tree. |
source | Uint8Array | Original parsed bytes. |
Exported types
Section titled “Exported types”| Type | Purpose | Notes |
|---|---|---|
SqlKindType | Union of all SqlKind values | Type-safe kind reference |
SqlFieldType | Union of all SqlField values | Type-safe field reference |
Configuration and Extension
Section titled “Configuration and Extension”No configuration options. SQL dialect detection is automatic based on input syntax.
Accessibility
Section titled “Accessibility”Accessibility requirements
Section titled “Accessibility requirements”- No direct accessibility surface. The SQL parser produces flat AST data structures.
Accessibility checklist
Section titled “Accessibility checklist”| Concern | Status |
|---|---|
| Generated output semantics | Not applicable (query format) |
| ARIA attributes in serialized output | Not applicable |
| Semantic element round-trip | Not applicable |
Security
Section titled “Security”Security considerations
Section titled “Security considerations”parseSqlnever throws on any byte sequence.
| Threat | Mitigation | Status |
|---|---|---|
| Malformed input byte sequence | Panic-free guarantee: all inputs accepted, errors produce LexError AST nodes | Implemented |
Companion packages
Section titled “Companion packages”| Package | Relationship | Layer | Notes |
|---|---|---|---|
@lanexio/parser-core | Requires | 1 | Provides LexTree, LexNode, LexCursor |
@lanexio/parser | Consumes | 6 | Unified entry point |
Beta status
Section titled “Beta status”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
Changelog
Section titled “Changelog”| Version | Date | Status | Notable changes |
|---|---|---|---|
0.0.1 | 2026-05-29 | Current | Initial beta release. Apache-2.0. |
Migration notes
Section titled “Migration notes”- This is a beta release. No migration guarantees until v1.0.0.
Related Content
Section titled “Related Content” Flat AST How the 16-byte node layout works.
Stability Guarantees Never-throw, panic-free, and 3-token recovery.