├── .gitignore ├── .npmignore ├── .travis.yml ├── Makefile ├── README.md ├── bin └── sqljs ├── doc └── ref │ ├── antlr │ ├── sql2003Lexer.g │ └── sql2003Parser.g │ └── savage │ ├── bnf2html.pl │ ├── bnf2yacc.pl │ ├── index.html │ ├── outer-joins.html │ ├── sql-2003-1.bnf │ ├── sql-2003-1.bnf.html │ ├── sql-2003-1.yacc │ ├── sql-2003-2.bnf │ ├── sql-2003-2.bnf.html │ ├── sql-2003-2.yacc │ ├── sql-2003-core-features.html │ ├── sql-2003-noncore-features.html │ ├── sql-92.bnf │ ├── sql-92.bnf.html │ ├── sql-92.yacc │ ├── sql-99.bnf │ ├── sql-99.bnf.html │ ├── sql-99.yacc │ └── sql-bnf.mk ├── examples └── browser │ ├── demo.browserified.js │ ├── demo.js │ └── index.html ├── grammar ├── 00-00-00-init-start.pegjs ├── 09-01-00-literal-value.pegjs ├── 09-01-01-string-literal.pegjs ├── 09-01-02-number-literal.pegjs ├── 09-01-05-boolean-literal.pegjs ├── 09-01-07-null.pegjs ├── 09-02-00-identifiers.pegjs ├── 09-05-00-expression.pegjs ├── 13-00-00-statement.pegjs ├── 13-01-00-data-definition.pegjs ├── 13-01-01-alter-database.pegjs ├── 13-01-06-alter-table.pegjs ├── 13-01-08-create-database.pegjs ├── 13-01-14-create-table.pegjs ├── 13-01-17-drop-database.pegjs ├── 13-02-00-data-manipulation.pegjs ├── 13-02-01-call.pegjs ├── 13-02-05-insert.pegjs ├── 13-02-09-select-statement.pegjs ├── 13-07-04-set.pegjs ├── 13-08-04-use.pegjs ├── 14-02-02-05-foreign-key.pegjs ├── 80-literal-datetime.pegjs └── 99-whitespace.pegjs ├── lib ├── error-formatter.js ├── parse-options.js ├── sqljs-cli.js ├── sqljs-parser.js └── sqljs.js ├── package.json └── tests └── parser ├── 09-01-01-string.js ├── 09-01-02-number.js ├── 09-02-00-identifiers.js ├── 09-05-00-expression.js ├── 13-01-08-create-database.js ├── 13-01-14-create-table.js └── common └── helper-rule-yields.js /.gitignore: -------------------------------------------------------------------------------- 1 | lib/sqljs-parser.pegjs 2 | 3 | lib-cov 4 | *.seed 5 | *.log 6 | *.csv 7 | *.dat 8 | *.out 9 | *.pid 10 | *.gz 11 | 12 | pids 13 | logs 14 | results 15 | 16 | node_modules 17 | npm-debug.log 18 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | node_modules 15 | npm-debug.log 16 | 17 | examples 18 | grammar 19 | *.pegjs 20 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 0.10 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | GRAMMAR_FILES = $(shell find ./grammar/*.pegjs | sort) 2 | 3 | CAT=cat 4 | RM=rm -f 5 | NODE=node 6 | PEGJS=./node_modules/.bin/pegjs --cache 7 | NODEUNIT=./node_modules/.bin/nodeunit 8 | BROWSERIFY=./node_modules/.bin/browserify 9 | 10 | all: lib examples 11 | 12 | lib: ./lib/sqljs-parser.pegjs ./lib/sqljs-parser.js 13 | 14 | clean: 15 | $(RM) ./lib/sqljs-parser.pegjs 16 | $(RM) ./lib/sqljs-parser.js 17 | $(RM) ./examples/browser/demo.browserified.js 18 | 19 | test: 20 | $(NODEUNIT) --reporter minimal ./tests/* 21 | 22 | ./lib/sqljs-parser.pegjs: $(GRAMMAR_FILES) 23 | $(CAT) $(GRAMMAR_FILES) > ./lib/sqljs-parser.pegjs || $(RM) ./lib/sqljs-parser.pegjs 24 | 25 | ./lib/sqljs-parser.js: ./lib/sqljs-parser.pegjs 26 | $(PEGJS) ./lib/sqljs-parser.pegjs ./lib/sqljs-parser.js || $(RM) ./lib/sqljs-parser.js 27 | 28 | examples: example-browser 29 | 30 | example-browser: examples/browser/demo.browserified.js lib 31 | 32 | examples/browser/demo.browserified.js: examples/browser/demo.js 33 | $(BROWSERIFY) ./examples/browser/demo.js -o ./examples/browser/demo.browserified.js 34 | 35 | .PHONY: all lib examples example-browser clean test 36 | 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | sqljs [](http://travis-ci.org/sqljs/node-sqljs) 2 | ===== 3 | 4 | [](https://david-dm.org/sqljs/node-sqljs) [](https://david-dm.org/sqljs/node-sqljs#info=devDependencies) [](https://gitter.im/sqljs/node-sqljs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 5 | [](https://gratipay.com/langpavel/) 6 | 7 | 8 | SQL parser for node.js 9 | 10 | Synopsis 11 | ======== 12 | * SQL parser useful for database abstraction layers and analyzers 13 | * Freeform syntax - it should be compatible with various SQL dialects 14 | 15 | Instalation 16 | =========== 17 | 18 | Because sqljs is still under heavy development, installation is better over git. 19 | In fact, at npm repository this package is still empty. 20 | 21 | Instalation via git: 22 | -------- 23 | 24 | git clone git://github.com/langpavel/node-sqljs.git sqljs && cd sqljs && npm install && make 25 | 26 | and optionally 27 | 28 | sudo npm link 29 | 30 | Instalation via npm: 31 | -------- 32 | 33 | npm install git://github.com/langpavel/node-sqljs.git 34 | 35 | or globally 36 | 37 | npm install -g git://github.com/langpavel/node-sqljs.git 38 | 39 | 40 | -------------------------------------------------------------------------------- /bin/sqljs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/sqljs-cli'); 4 | -------------------------------------------------------------------------------- /doc/ref/savage/bnf2html.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | # 3 | # @(#)$Id: bnf2html.pl,v 3.7 2005/07/13 18:32:35 jleffler Exp $ 4 | # 5 | # Convert SQL-92, SQL-99 BNF plain text file into hyperlinked HTML. 6 | 7 | use strict; 8 | use POSIX qw(strftime); 9 | 10 | my(%rules); # Indexed by rule names w/o angle-brackets; each entry is a ref to a hash. 11 | my(%keywords); # Index by keywords; each entry is a ref to a hash. 12 | 13 | use constant debug => 0; 14 | 15 | sub top 16 | { 17 | print "
\n\n"; 18 | } 19 | 20 | # Usage: add_entry(\%keywords, $keyword, $rule); 21 | # Usage: add_entry(\%rules, $rhs, $rule); 22 | sub add_entry 23 | { 24 | my($reflist, $lhs, $rhs) = @_; 25 | ${$reflist}{$lhs} = {} unless defined ${$reflist}{$lhs}; 26 | ${$reflist}{$lhs}{$rhs} = 1; 27 | } 28 | 29 | sub add_refs 30 | { 31 | my($def, $tail) = @_; 32 | print "\n\n" if debug; 33 | return if $tail =~ m/!!/; 34 | while ($tail) 35 | { 36 | $tail =~ s/^\s*//; 37 | if ($tail =~ m%^\<([-:/\w\s]+)\>%) 38 | { 39 | print "\n" if debug; 40 | add_entry(\%rules, $1, $def); 41 | $tail =~ s%^\<([-:/\w\s]+)\>%%; 42 | } 43 | elsif ($tail =~ m%^([-:/\w]+)%) 44 | { 45 | my($token) = $1; 46 | print "\n" if debug; 47 | add_entry(\%keywords, $token, $def) if $token =~ m%[[:alpha:]][[:alpha:]]% || $token eq 'C'; 48 | $tail =~ s%^[-:/\w]+%%; 49 | } 50 | else 51 | { 52 | # Otherwise, it is punctuation (such as the BNF metacharacters). 53 | $tail =~ s%^[^-:/\w]%%; 54 | } 55 | } 56 | } 57 | 58 | # NB: webcode replaces tabs with blanks! 59 | open WEBCODE, "webcode @ARGV |" or die "$!"; 60 | 61 | $_ =\n";
196 | print "Derived from $v1\n";
197 | my $today = iso8601_format(time);
198 | print "
\n";
199 | print "Generated on $today by $v2\n";
200 | print "
\n';
210 | print qq' <$def> ::=';
211 | $tcount = 0;
212 | if ($tail)
213 | {
214 | add_refs($def, $tail);
215 | print " ";
216 | $tcount = print_tail($tail, $tcount);
217 | }
218 | print "\n";
219 | }
220 | elsif (/^\s/)
221 | {
222 | # Expansion line
223 | add_refs($def, $_);
224 | print "
";
225 | $tcount = print_tail($_, $tcount);
226 | }
227 | elsif (m/^--[\/]?(\w+)/)
228 | {
229 | # Pseudo-directive line in lower-case
230 | # Print a 'Top' link before
Start symbol: $start
\n'; 250 | } 251 | else 252 | { 253 | # Anything unrecognized passed through unchanged! 254 | print "$_\n"; 255 | } 256 | } 257 | 258 | # Print index of initial letters for keywords. 259 | sub print_index_key 260 | { 261 | my($prefix, @keys) = @_; 262 | my %letters = (); 263 | foreach my $keyword (@keys) 264 | { 265 | my $initial = uc substr $keyword, 0, 1; 266 | $letters{$initial} = 1; 267 | } 268 | foreach my $letter ('A' .. 'Z') 269 | { 270 | if (defined($letters{$letter})) 271 | { 272 | print qq' $letter \n'; 273 | } 274 | else 275 | { 276 | print qq'$letter\n'; 277 | } 278 | } 279 | print "\n"; 280 | } 281 | 282 | ### Generate cross-reference tables 283 | 284 | { 285 | print "Rule (non-terminal) | Rules using it |
---|---|
$label $rule | \n'; 306 | my $pad = ""; 307 | foreach my $ref (sort { uc $a cmp uc $b } keys %{$rules{$rule}}) 308 | { 309 | print qq'$pad <$ref> \n'; 310 | $pad = " "; 311 | } 312 | print " | \n
Keyword | Rules using it |
---|---|
$label $keyword | \n'; 339 | my $pad = ""; 340 | foreach my $ref (sort { uc $a cmp uc $b } keys %{$keywords{$keyword}}) 341 | { 342 | print qq'$pad <$ref> \n'; 343 | $pad = " "; 344 | } 345 | print " | \n