rebel 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rebel/sql.rb +46 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4183b987662f827d6b32d29a8ab27c296dacdb82
|
4
|
+
data.tar.gz: 3835ab7325bb2262aa2433be7056265ed6adc0b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9586ef0f6aca3e96c5283817d8b61ad54d24f90a9018817eeca1223041a3a31e36c428919172a16c79e318c767f00e12f510d23483e778ec53da1431d9849e73
|
7
|
+
data.tar.gz: f3f8eebeefaf6614e02f35b61a20475083ee77037b8f6169732cb49323a11bce9c3f91b4b5695e571c4df049ce55216097f823392d4f1e91e2b64314919945d8
|
data/lib/rebel/sql.rb
CHANGED
@@ -13,13 +13,18 @@ module Rebel::SQL
|
|
13
13
|
exec(Rebel::SQL.drop_table(table_name))
|
14
14
|
end
|
15
15
|
|
16
|
-
def select(*fields, from: nil, where: nil, inner: nil, left: nil, right: nil)
|
16
|
+
def select(*fields, distinct: distinct, from: nil, where: nil, inner: nil, left: nil, right: nil, group: nil, order: nil, limit: nil, offset: nil)
|
17
17
|
exec(Rebel::SQL.select(*fields,
|
18
|
+
distinct: distinct,
|
18
19
|
from: from,
|
19
20
|
where: where,
|
20
21
|
inner: inner,
|
21
22
|
left: left,
|
22
|
-
right: right
|
23
|
+
right: right,
|
24
|
+
group: group,
|
25
|
+
order: order,
|
26
|
+
limit: limit,
|
27
|
+
offset: offset))
|
23
28
|
end
|
24
29
|
|
25
30
|
def insert_into(table_name, *rows)
|
@@ -85,6 +90,18 @@ module Rebel::SQL
|
|
85
90
|
clause.any? ? on(*clause) : self
|
86
91
|
end
|
87
92
|
|
93
|
+
def having(*clause)
|
94
|
+
Raw.new(self + " HAVING #{Rebel::SQL.and_clause(*clause)}")
|
95
|
+
end
|
96
|
+
|
97
|
+
def asc
|
98
|
+
Raw.new(self + " ASC")
|
99
|
+
end
|
100
|
+
|
101
|
+
def desc
|
102
|
+
Raw.new(self + " DESC")
|
103
|
+
end
|
104
|
+
|
88
105
|
def and(*clause)
|
89
106
|
Raw.new("#{self.parens?} AND #{Rebel::SQL.and_clause(*clause)}")
|
90
107
|
end
|
@@ -178,13 +195,17 @@ module Rebel::SQL
|
|
178
195
|
SQL
|
179
196
|
end
|
180
197
|
|
181
|
-
def select(*fields, from: nil, where: nil, inner: nil, left: nil, right: nil)
|
198
|
+
def select(*fields, distinct: nil, from: nil, where: nil, inner: nil, left: nil, right: nil, group: nil, order: nil, limit: nil, offset: nil)
|
182
199
|
raw <<-SQL
|
183
|
-
SELECT #{names(*
|
200
|
+
SELECT #{distinct ? "DISTINCT #{names(*distinct)}" : names(*fields)}
|
201
|
+
#{from?(from)}
|
184
202
|
#{inner?(inner)}
|
185
203
|
#{left?(left)}
|
186
204
|
#{right?(right)}
|
187
205
|
#{where?(where)}
|
206
|
+
#{group?(group)}
|
207
|
+
#{order?(order)}
|
208
|
+
#{limit?(limit, offset)}
|
188
209
|
SQL
|
189
210
|
end
|
190
211
|
|
@@ -231,6 +252,10 @@ module Rebel::SQL
|
|
231
252
|
end
|
232
253
|
alias fn function
|
233
254
|
|
255
|
+
def by(*n)
|
256
|
+
raw("BY #{names(*n)}")
|
257
|
+
end
|
258
|
+
|
234
259
|
def count(*n)
|
235
260
|
raw("COUNT(#{names(*n)})")
|
236
261
|
end
|
@@ -284,7 +309,7 @@ module Rebel::SQL
|
|
284
309
|
when TrueClass, FalseClass then raw(v ? 'TRUE' : 'FALSE')
|
285
310
|
when Date, Time, DateTime then value(v.iso8601)
|
286
311
|
when nil then raw 'NULL'
|
287
|
-
else raise NotImplementedError, v.inspect
|
312
|
+
else raise NotImplementedError, "#{v.class}: #{v.inspect}"
|
288
313
|
end
|
289
314
|
end
|
290
315
|
|
@@ -329,6 +354,10 @@ module Rebel::SQL
|
|
329
354
|
end.join(' AND ')
|
330
355
|
end
|
331
356
|
|
357
|
+
def from?(from)
|
358
|
+
from ? "FROM #{name(from)}" : nil
|
359
|
+
end
|
360
|
+
|
332
361
|
def where?(*clause)
|
333
362
|
clause.any? ? "WHERE #{and_clause(*clause)}" : nil
|
334
363
|
end
|
@@ -344,5 +373,17 @@ module Rebel::SQL
|
|
344
373
|
def right?(join)
|
345
374
|
join ? "RIGHT #{join}" : nil
|
346
375
|
end
|
376
|
+
|
377
|
+
def group?(group)
|
378
|
+
group ? "GROUP #{name(group)}" : nil
|
379
|
+
end
|
380
|
+
|
381
|
+
def order?(order)
|
382
|
+
order ? "ORDER #{name(order)}" : nil
|
383
|
+
end
|
384
|
+
|
385
|
+
def limit?(limit, offset)
|
386
|
+
limit ? "LIMIT #{value(limit)}" << (offset ? " OFFSET #{offset}" : "") : nil
|
387
|
+
end
|
347
388
|
end
|
348
389
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rebel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loic Nageleisen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: SQL-flavoured Ruby, or is it the other way around?
|
14
14
|
email: loic.nageleisen@gmail.com
|