nql 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/nql/grammar.rb +18 -6
- data/lib/nql/grammar.treetop +2 -1
- data/lib/nql/version.rb +1 -1
- data/spec/comparison_parser_spec.rb +10 -1
- data/spec/ransack_spec.rb +8 -0
- data/spec/sql_spec.rb +5 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# NQL
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/gabynaiman/nql.png)](https://travis-ci.org/gabynaiman/nql)
|
3
|
+
[![Build Status](https://travis-ci.org/gabynaiman/nql.png?branch=master)](https://travis-ci.org/gabynaiman/nql)
|
4
4
|
|
5
5
|
Natural Query Language built on top of ActiveRecord and Ransack
|
6
6
|
|
data/lib/nql/grammar.rb
CHANGED
@@ -394,6 +394,7 @@ module NQL
|
|
394
394
|
'<' => 'lt',
|
395
395
|
'<=' => 'lteq',
|
396
396
|
':' => 'cont',
|
397
|
+
'!:' => 'not_cont',
|
397
398
|
'~' => 'matches'
|
398
399
|
}
|
399
400
|
comparators[text_value]
|
@@ -484,18 +485,29 @@ module NQL
|
|
484
485
|
if r8
|
485
486
|
r1 = r8
|
486
487
|
else
|
487
|
-
if has_terminal?('
|
488
|
-
r9 = instantiate_node(SyntaxNode,input, index...(index +
|
489
|
-
@index +=
|
488
|
+
if has_terminal?('!:', false, index)
|
489
|
+
r9 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
490
|
+
@index += 2
|
490
491
|
else
|
491
|
-
terminal_parse_failure('
|
492
|
+
terminal_parse_failure('!:')
|
492
493
|
r9 = nil
|
493
494
|
end
|
494
495
|
if r9
|
495
496
|
r1 = r9
|
496
497
|
else
|
497
|
-
|
498
|
-
|
498
|
+
if has_terminal?('~', false, index)
|
499
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
500
|
+
@index += 1
|
501
|
+
else
|
502
|
+
terminal_parse_failure('~')
|
503
|
+
r10 = nil
|
504
|
+
end
|
505
|
+
if r10
|
506
|
+
r1 = r10
|
507
|
+
else
|
508
|
+
@index = i1
|
509
|
+
r1 = nil
|
510
|
+
end
|
499
511
|
end
|
500
512
|
end
|
501
513
|
end
|
data/lib/nql/grammar.treetop
CHANGED
@@ -68,7 +68,7 @@ module NQL
|
|
68
68
|
end
|
69
69
|
|
70
70
|
rule comparator
|
71
|
-
('=' / '!=' / '>' / '>=' / '<' / '<=' / ':' / '~')+ {
|
71
|
+
('=' / '!=' / '>' / '>=' / '<' / '<=' / ':' / '!:' / '~')+ {
|
72
72
|
def to_ransack
|
73
73
|
comparators = {
|
74
74
|
'=' => 'eq',
|
@@ -78,6 +78,7 @@ module NQL
|
|
78
78
|
'<' => 'lt',
|
79
79
|
'<=' => 'lteq',
|
80
80
|
':' => 'cont',
|
81
|
+
'!:' => 'not_cont',
|
81
82
|
'~' => 'matches'
|
82
83
|
}
|
83
84
|
comparators[text_value]
|
data/lib/nql/version.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe NQL::SyntaxParser, '-> Comparison' do
|
@@ -62,6 +63,14 @@ describe NQL::SyntaxParser, '-> Comparison' do
|
|
62
63
|
tree.comparison.value.text_value.should eq 'value'
|
63
64
|
end
|
64
65
|
|
66
|
+
it 'Not contains' do
|
67
|
+
tree = parser.parse('var !: value')
|
68
|
+
|
69
|
+
tree.comparison.variable.text_value.should eq 'var'
|
70
|
+
tree.comparison.comparator.text_value.should eq '!:'
|
71
|
+
tree.comparison.value.text_value.should eq 'value'
|
72
|
+
end
|
73
|
+
|
65
74
|
it 'Matches' do
|
66
75
|
tree = parser.parse('var ~ value')
|
67
76
|
|
@@ -135,7 +144,7 @@ describe NQL::SyntaxParser, '-> Comparison' do
|
|
135
144
|
|
136
145
|
|
137
146
|
it 'With utf8 chars and symbols' do
|
138
|
-
utf8_symbols = "
|
147
|
+
utf8_symbols = "ÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜàáâãäçèéêëìíîïñòóôõöùúûü"
|
139
148
|
tree = parser.parse("var = .#+-#{utf8_symbols}")
|
140
149
|
tree.comparison.value.text_value.should eq ".#+-#{utf8_symbols}"
|
141
150
|
end
|
data/spec/ransack_spec.rb
CHANGED
@@ -62,6 +62,14 @@ describe 'Ransack Query' do
|
|
62
62
|
q[:c][0].should have_value '1234'
|
63
63
|
end
|
64
64
|
|
65
|
+
it 'Not contains' do
|
66
|
+
q = parser.parse('id !: 1234').to_ransack
|
67
|
+
|
68
|
+
q[:c][0].should have_attribute 'id'
|
69
|
+
q[:c][0].should have_predicate 'not_cont'
|
70
|
+
q[:c][0].should have_value '1234'
|
71
|
+
end
|
72
|
+
|
65
73
|
it 'Matches' do
|
66
74
|
q = parser.parse('id ~ 1234').to_ransack
|
67
75
|
|
data/spec/sql_spec.rb
CHANGED
@@ -45,6 +45,11 @@ describe 'SQL generation' do
|
|
45
45
|
Country.nql(q).should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE (\"countries\".\"name\" LIKE '%abcd%')"
|
46
46
|
end
|
47
47
|
|
48
|
+
it 'Not contains' do
|
49
|
+
q = 'name !: abcd'
|
50
|
+
Country.nql(q).should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE (\"countries\".\"name\" NOT LIKE '%abcd%')"
|
51
|
+
end
|
52
|
+
|
48
53
|
it 'Matches' do
|
49
54
|
q = 'name ~ abcd'
|
50
55
|
Country.nql(q).should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE (\"countries\".\"name\" LIKE 'abcd')"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: treetop
|