Registry / database / floral-sql-parser

floral-sql-parser

JSON →
library1.2.13jsnpmunverified

Parse SQL SELECT statements into an abstract syntax tree (AST) and convert ASTs back to SQL. Current stable version is 1.2.13. Released as needed. Key differentiator: lightweight, focused only on SELECT statements, with AST-to-SQL conversion. It is a fork of the original cht-ui-sql-parser, maintained under the floral-sql-parser npm name. Supports Node >=10 with CommonJS only (no ESM).

npm install floral-sql-parser
INSTALL
IMPORT
SIG · FLORAL-SQL-PARSER
F
floral-sql-parser
databasejavascriptv1.2.13
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.

parse
const { parse } = require('floral-sql-parser')
import { parse } from 'floral-sql-parser'
This package does not support ESM imports; use CommonJS require().
stringify
const { stringify } = require('floral-sql-parser')
const stringify = require('floral-sql-parser').stringify
Named export, accessible via destructuring require.
Parser
const { Parser } = require('floral-sql-parser')
const Parser = require('floral-sql-parser').default
Parser is a named export, not default.

Parses a SELECT statement into an AST and converts the AST back to the original SQL.

const { parse, stringify } = require('floral-sql-parser'); const sql = 'SELECT id, name FROM users WHERE age > 21'; const ast = parse(sql); console.log(JSON.stringify(ast, null, 2)); const backToSql = stringify(ast); console.log(backToSql); // 'SELECT id, name FROM users WHERE age > 21'
Debug
Known issues
gotchaOnly SELECT statements are supported; parsing UPDATE, DELETE, or INSERT will throw an error.
fix
Ensure input SQL is a SELECT statement.
affects: >=1.0.0
gotchaThe AST returned by parse() uses a specific schema that may change between minor versions without warning.
fix
Pin the package version and do not rely on internal AST node shapes across updates.
affects: >=1.0.0 <2.0.0
gotchaCommonJS only; ESM import (e.g., import { parse } from 'floral-sql-parser') will fail.
fix
Use require() or use a dynamic import wrapper (if using ESM).
affects: >=1.0.0
deprecatedThe original package name 'cht-ui-sql-parser' is no longer maintained; use 'floral-sql-parser' instead.
fix
Update package.json dependency to 'floral-sql-parser'.
affects: >=1.0.0
Errors
Common errors & fixes
Error: SELECT statement expected, got 'UPDATE'
The input SQL is not a SELECT statement.
fix
Only pass SELECT statements to parse().
TypeError: parse is not a function
Incorrect import method (e.g., using ESM import on a CommonJS-only package).
fix
Use const { parse } = require('floral-sql-parser').
Upgrade
Version history
1.2.13latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
floral-sql-parser — npm install floral-sql-parser · libregistry