Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit d0b9353

Browse files
committed
Rewrite README.md based on recent changes.
Refs #26 Refs #27
1 parent 90b31bb commit d0b9353

File tree

2 files changed

+39
-133
lines changed

2 files changed

+39
-133
lines changed

Gruntfile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ module.exports = function(grunt) {
360360
grunt.registerTask('default', [
361361
'dist'
362362
]);
363-
// Create new build in .tmp/ folder
363+
// Create new build of the parser in .tmp/ folder
364364
grunt.registerTask('build', [
365365
'clean:build',
366366
'shell:build',
367367
'babel:build'
368368
]);
369-
// Create new lib folder
369+
// Create new lib/ folder containing the release version of the parser
370370
grunt.registerTask('dist', [
371371
'demobuild',
372372
'clean:release',
@@ -404,7 +404,7 @@ module.exports = function(grunt) {
404404
]);
405405
// Build the parser to .tmp/ and run tests, but take the output from the
406406
// parser use it to overwrite the existing test JSON files in test/json/
407-
grunt.registerTask('rewrite-json', [
407+
grunt.registerTask('rewritejson', [
408408
'build', 'shell:rewrite'
409409
]);
410410
// Rebuild the interactive demo site to .tmp/

README.md

Lines changed: 36 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
[![devDependencies Status Image](https://img.shields.io/david/dev/codeschool/sqlite-parser.svg)](https://github.com/codeschool/sqlite-parser/)
66
[![License Type Image](https://img.shields.io/github/license/codeschool/sqlite-parser.svg)](https://github.com/codeschool/sqlite-parser/blob/master/LICENSE)
77

8-
This library parses SQLite queries, using JavaScript, and generates
9-
_abstract syntax tree_ (AST) representations of the input strings. A
10-
syntax error is produced if an AST cannot be generated.
8+
This JavaScript library parses SQLite queries to generate
9+
_abstract syntax tree_ (AST) representations of the parsed statements.
10+
11+
Try out the
12+
[interactive demo]((http://codeschool.github.io/sqlite-parser/demo/))
13+
to see it in action.
1114

1215
**This parser is written against the [SQLite 3 spec](https://www.sqlite.org/lang.html).**
1316

@@ -17,25 +20,22 @@ syntax error is produced if an AST cannot be generated.
1720
npm install sqlite-parser
1821
```
1922

20-
### Beta Version Available
23+
### Install as a global module
2124

22-
If you want the latest and greatest, install the _beta_ version of the parser (currently [v1.0.0-beta](https://github.com/codeschool/sqlite-parser/releases/tag/v1.0.0-beta)) with loads of new features and fixes.
25+
Use the command-line interface of the parser by installing it as a global module.
26+
The `sqlite-parser` command is then available to use to parse input SQL files and
27+
write the results to stdout or a JSON file. Additional usage
28+
instructions and options available through `sqlite-parser --help`.
2329

2430
```
25-
npm install sqlite-parser@beta
31+
npm i -g sqlite-parser
2632
```
2733

28-
## Demo
29-
30-
There is an interactive demo of the parser hosted
31-
[at this location](http://codeschool.github.io/sqlite-parser/demo/). You
32-
can run a copy of the demo on your local machine by cloning this repository
33-
and then using the command `grunt live`.
34-
35-
## Usage
34+
## Basic Usage
3635

37-
The library exposes a function that accepts two arguments: a string
38-
containing SQL to parse and a callback function.
36+
The library exposes a function that accepts two arguments: a string containing
37+
SQL to parse and a callback function. If an AST cannot be generated from the
38+
input string then a descriptive error is generated.
3939

4040
If invoked without a callback function the parser will runs synchronously and
4141
return the resulting AST or throw an error if one occurs.
@@ -50,14 +50,14 @@ console.log(ast);
5050
// async
5151
sqliteParser(query, function (err, ast) {
5252
if (err) {
53-
console.log(err);
53+
console.error(err);
5454
return;
5555
}
5656
console.log(ast);
5757
});
5858
```
5959

60-
### Use parser on Node streams *experimental*
60+
## Use parser on Node streams *(experimental)*
6161

6262
This library also includes *experimental* support as a
6363
[stream transform](https://nodejs.org/api/stream.html) that can accept a
@@ -76,7 +76,7 @@ readStream.pipe(parserTransform);
7676
parserTransform.pipe(process.stdout);
7777

7878
parserTransform.on('error', function (err) {
79-
console.log(err);
79+
console.error(err);
8080
process.exit(1);
8181
});
8282

@@ -85,9 +85,9 @@ parserTransform.on('finish', function () {
8585
});
8686
```
8787

88-
_Note:_ To pipe the output into a file that contains a single valid JSON
89-
structure, the output of the parser steam transform needs to be wrapped in
90-
statement list node where every statement is separated by a comma.
88+
To pipe the output into a file that contains a single valid JSON structure, the
89+
output of the parser steam transform needs to be wrapped in statement list node
90+
where every statement is separated by a comma.
9191

9292
``` javascript
9393
var fs = require('fs');
@@ -102,7 +102,7 @@ parserTransform.pipe(singleNodeTransform);
102102
singleNodeTransform.pipe(writeStream);
103103

104104
parserTransform.on('error', function (err) {
105-
console.log(err);
105+
console.error(err);
106106
process.exit(1);
107107
});
108108

@@ -111,28 +111,22 @@ writeStream.on('finish', function () {
111111
});
112112
```
113113

114-
## Syntax Errors
115-
116-
This parser will try to create _smart_ error messages when it cannot parse
117-
some input SQL. In addition to an approximate location for the syntax error,
118-
the parser will attempt to describe the area of concern
119-
(e.g.: `Syntax error found near Column Identifier (WHERE Clause)`).
120-
121114
## AST
122115

123-
**NOTE: The SQLite AST is a work-in-progress and subject to change.**
116+
The AST is stable as of release `1.0.0`. However, if changes need to be made to
117+
improve consistency between node types, they will be explicitly listed in the
118+
[CHANGELOG](https://github.com/codeschool/sqlite-parser/blob/master/CHANGELOG.md).
124119

125120
### Example
126121

127122
You can provide one or more SQL statements at a time. The resulting AST object
128-
has, at the highest level, a `statement` key that consists of an array containing
129-
the parsed statements.
123+
has, at the highest level, a statement list node that contains an array of
124+
statements.
130125

131126
#### Input SQL
132127

133128
``` sql
134129
SELECT
135-
MIN(honey) AS "Min Honey",
136130
MAX(honey) AS "Max Honey"
137131
FROM
138132
BeeHive
@@ -149,26 +143,6 @@ FROM
149143
"type": "statement",
150144
"variant": "select",
151145
"result": [
152-
{
153-
"type": "function",
154-
"name": {
155-
"type": "identifier",
156-
"variant": "function",
157-
"name": "min"
158-
},
159-
"args": {
160-
"type": "expression",
161-
"variant": "list",
162-
"expression": [
163-
{
164-
"type": "identifier",
165-
"variant": "column",
166-
"name": "honey"
167-
}
168-
]
169-
},
170-
"alias": "Min Honey"
171-
},
172146
{
173147
"type": "function",
174148
"name": {
@@ -200,82 +174,14 @@ FROM
200174
}
201175
```
202176

203-
## Contributing
204-
205-
Once the dependencies are installed, start development with the following command:
206-
207-
```
208-
grunt test-watch
209-
```
177+
## Syntax Errors
210178

211-
which will automatically compile the parser and run the tests in
212-
`test/core/**/*-spec.js` each time a change is made to the tests and/or
213-
the source code.
214-
215-
Optionally, run `grunt debug` to get AST output from each test in addition to
216-
live reloading.
217-
218-
Finally, you should run `grunt release` before creating any PR. **Do not** change
219-
the version number in `package.json` inside of the pull request.
220-
221-
### Writing tests
222-
223-
Each test refers to a SQL input file in `test/sql/` and an expected output
224-
JSON AST file.
225-
226-
For example a `describe()` block with the title `parent block` that contains an
227-
`it()` block named `super test 2` will look for the SQL input at
228-
`test/sql/parent-block/super-test-2.sql` and the JSON AST at
229-
`test/json/parent-block/super-test-2.json`.
230-
231-
There are three options for the test helpers exposed by `tree`:
232-
- Assert that the test file successfully generates _any_ valid AST
233-
``` javascript
234-
tree.ok(this, done);
235-
```
236-
237-
- Assert that the test file generates an AST that exactly matches the expected output JSON file
238-
``` javascript
239-
tree.equals(this, done);
240-
```
241-
242-
- `tree.error()` to assert that a test throws an error
243-
- Assert a specific error `message` for the thrown error
244-
``` javascript
245-
tree.error('My error message.', this, done);
246-
```
247-
- Assert an object of properties that all exist in the thrown error object
248-
``` javascript
249-
tree.error({
250-
message: 'You forgot to add a boop to the beep.',
251-
location: {
252-
start: { offset: 0, line: 1, column: 1 },
253-
end: { offset: 0, line: 1, column: 1 }
254-
}
255-
}, this, done)
256-
```
179+
This parser will try to create *descriptive* error messages when it cannot parse
180+
some input SQL. In addition to an approximate location for the syntax error,
181+
the parser will attempt to describe the area of concern
182+
(e.g.: `Syntax error found near Column Identifier (WHERE Clause)`).
257183

258-
``` javascript
259-
/* All the helper functions in `/test/helpers.js` are already available
260-
* and do not need to be explicitly imported.
261-
*/
262-
describe('select', function () {
263-
/* Test SQL: test/sql/select/basic-select.sql
264-
* Expected JSON AST: test/json/select/basic-select.json
265-
*/
266-
it('basic select', function (done) {
267-
tree.equals(this, done);
268-
});
269-
});
184+
## Contributing
270185

271-
describe('parse errors', function (done) {
272-
/* Test SQL: test/sql/parse-errors/parse-error-1.sql
273-
* Expected JSON AST: test/json/parse-errors/parse-error-1.json
274-
*/
275-
it('parse error 1', function(done) {
276-
tree.error({
277-
'message': 'Syntax error found near Column Identifier (WHERE Clause)'
278-
}, this, done);
279-
});
280-
});
281-
```
186+
Contributions are welcome! You can get started by checking out the
187+
[contributing guidelines](https://github.com/codeschool/sqlite-parser/blob/master/CHANGELOG.md).

0 commit comments

Comments
 (0)