# qh-flora-sql-parser

> Parse SQL (select) statements into abstract syntax tree (AST) and convert ASTs back to SQL.

Latest version **0.10.1** (published 2022-07-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install qh-flora-sql-parser
pnpm add qh-flora-sql-parser
yarn add qh-flora-sql-parser
bun add qh-flora-sql-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.10.1 |
| Published | 2022-07-15 |
| First published | 2017-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 3 |
| Unpacked size | 340.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | BörseGo AG |
| Maintainers | noteon |
| Keywords | sql, parser, ast |

## Links

- npm: https://www.npmjs.com/package/qh-flora-sql-parser
- Repository: https://github.com/qing-hai/flora-sql-parser
- Issues: https://github.com/qing-hai/flora-sql-parser/issues
- npm.io page: https://npm.io/package/qh-flora-sql-parser

## Dependencies (3)

- [has](https://npm.io/package/has.md) ^1.0.1
- [pegjs](https://npm.io/package/pegjs.md) ^0.10.0
- [flora-errors](https://npm.io/package/flora-errors.md) ^0.7.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.10.1 (latest) — 2022-07-15
- 0.9.3 — 2020-08-24
- 0.9.2 — 2020-08-09
- 0.9.1 — 2020-07-07
- 0.8.1 — 2020-06-22
- 0.7.22 — 2020-05-17
- 0.7.21 — 2018-02-23
- 0.7.20 — 2018-02-22
- 0.7.19 — 2018-02-06
- 0.7.18 — 2018-02-05
- 0.7.17 — 2018-01-30
- 0.7.16 — 2018-01-29
- 0.7.15 — 2018-01-26
- 0.7.14 — 2018-01-25
- 0.7.13 — 2018-01-23
- … 9 more at https://npm.io/package/qh-flora-sql-parser/versions

## README

Flora SQL Parser
================

[![Build Status](https://travis-ci.org/godmodelabs/flora-sql-parser.svg?branch=master)](https://travis-ci.org/godmodelabs/flora-sql-parser)
[![NPM version](https://badge.fury.io/js/flora-sql-parser.svg)](https://www.npmjs.com/package/flora-sql-parser)
[![Dependencies](https://img.shields.io/david/godmodelabs/flora-sql-parser.svg)](https://david-dm.org/godmodelabs/flora-sql-parser)

Parse simple SQL statements into an abstract syntax tree (AST) and convert it back to SQL.


Usage
-----

#### Create AST for SQL statement:

```javascript
const Parser = require('flora-sql-parser').Parser;
const parser = new Parser();
const ast = parser.parse('SELECT * FROM t');

console.log(ast);
```

#### Convert AST back to SQL:

```javascript
const Parser = require('flora-sql-parser').Parser;
const ast = (new Parser()).parse('SELECT * FROM t');
const toSQL = require('flora-sql-parser').util.astToSQL;

console.log(toSQL(ast));
```

The generated SQL is ANSI SQL compliant. To run those queries on MySQL, make sure you set correct SQL mode
```sql
SET SESSION sql_mode = 'ANSI';
```
before running any query.

Acknowledgement
--------------

This project is based on the SQL parser extracted from Alibaba's [nquery](https://github.com/alibaba/nquery) module.  

License
-------

[MIT](LICENSE)

---
_Source: https://npm.io/package/qh-flora-sql-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
