sql-parser-vlad 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -77,6 +77,8 @@ rule
77
77
  DESC { [:DESC, text] }
78
78
  CURRENT_USER { [:CURRENT_USER, text] }
79
79
  VALUES { [:VALUES, text] }
80
+ LIMIT { [:LIMIT, text] }
81
+ OFFSET { [:OFFSET, text] }
80
82
 
81
83
  # tokens
82
84
  E { [:E, text] }
@@ -198,6 +198,12 @@ class SQLParser::Parser < Racc::Parser
198
198
  when (text = @ss.scan(/VALUES/i))
199
199
  action { [:VALUES, text] }
200
200
 
201
+ when (text = @ss.scan(/LIMIT/i))
202
+ action { [:LIMIT, text] }
203
+
204
+ when (text = @ss.scan(/OFFSET/i))
205
+ action { [:OFFSET, text] }
206
+
201
207
  when (text = @ss.scan(/E/i))
202
208
  action { [:E, text] }
203
209
 
@@ -60,7 +60,8 @@ module SQLParser
60
60
  o.from_clause,
61
61
  o.where_clause,
62
62
  o.group_by_clause,
63
- o.having_clause
63
+ o.having_clause,
64
+ o.limit_clause
64
65
  ].compact.collect { |e| visit(e) }.join(' ')
65
66
  end
66
67
 
@@ -92,6 +93,14 @@ module SQLParser
92
93
  "WHERE #{visit(o.search_condition)}"
93
94
  end
94
95
 
96
+ def visit_LimitClause(o)
97
+ if o.offset.nil?
98
+ "LIMIT #{o.limit}"
99
+ else
100
+ "LIMIT #{o.limit} OFFSET #{o.offset}"
101
+ end
102
+ end
103
+
95
104
  def visit_On(o)
96
105
  "ON #{visit(o.search_condition)}"
97
106
  end
@@ -111,17 +111,19 @@ module SQLParser
111
111
 
112
112
  class TableExpression < Node
113
113
 
114
- def initialize(from_clause, where_clause = nil, group_by_clause = nil, having_clause = nil)
114
+ def initialize(from_clause, where_clause = nil, group_by_clause = nil, having_clause = nil, limit_clause = nil)
115
115
  @from_clause = from_clause
116
116
  @where_clause = where_clause
117
117
  @group_by_clause = group_by_clause
118
118
  @having_clause = having_clause
119
+ @limit_clause = limit_clause
119
120
  end
120
121
 
121
122
  attr_reader :from_clause
122
123
  attr_reader :where_clause
123
124
  attr_reader :group_by_clause
124
125
  attr_reader :having_clause
126
+ attr_reader :limit_clause
125
127
 
126
128
  end
127
129
 
@@ -191,6 +193,16 @@ module SQLParser
191
193
 
192
194
  end
193
195
 
196
+ class LimitClause < Node
197
+
198
+ def initialize(limit, offset)
199
+ @limit = limit
200
+ @offset = offset
201
+ end
202
+
203
+ attr_reader :limit, :offset
204
+ end
205
+
194
206
  class On < Node
195
207
 
196
208
  def initialize(search_condition)
@@ -1,5 +1,5 @@
1
1
  module SQLParser
2
2
 
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql-parser-vlad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dray Lacy