rebel 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rebel/sql.rb +38 -42
- 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: 32fd955629a7dbd8738111e47395bbe7cd007792
|
4
|
+
data.tar.gz: a1c33efb78711424dfcef3b13c2bf0e775138cdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db54aa215e1d4c7e748d1ed04b898129304c8b668966fd32bd31f09374368782f1fbe9ffd249ce9deabe15ee079bcbc54badd3daddb19e410019301ef48a32e9
|
7
|
+
data.tar.gz: 3d230eac6c296658d998b627910b69039e735abb9ca2da56cc665ec98e6e9a61f6f8e73a9b50cb031138c1e2d85235faa89462c25d30568dd3e18b2bc400ea93
|
data/lib/rebel/sql.rb
CHANGED
@@ -183,67 +183,59 @@ module Rebel
|
|
183
183
|
end
|
184
184
|
|
185
185
|
def create_table(table_name, desc)
|
186
|
-
raw
|
187
|
-
CREATE TABLE #{name(table_name)} (
|
188
|
-
#{list(desc.map { |k, v| "#{name(k)} #{v}" })}
|
189
|
-
)
|
190
|
-
SQL
|
186
|
+
raw %[CREATE TABLE #{name(table_name)} (#{list(desc.map { |k, v| "#{name(k)} #{v}" })})]
|
191
187
|
end
|
192
188
|
|
193
189
|
def drop_table(table_name)
|
194
|
-
raw
|
195
|
-
DROP TABLE #{name(table_name)}
|
196
|
-
SQL
|
190
|
+
raw "DROP TABLE #{name(table_name)}"
|
197
191
|
end
|
198
192
|
|
199
193
|
def select(*fields, distinct: nil, from: nil, where: nil, inner: nil, left: nil, right: nil, group: nil, order: nil, limit: nil, offset: nil)
|
200
|
-
raw
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
194
|
+
raw [
|
195
|
+
"SELECT #{distinct ? "DISTINCT #{names(*distinct)}" : names(*fields)}",
|
196
|
+
from?(from),
|
197
|
+
inner?(inner),
|
198
|
+
left?(left),
|
199
|
+
right?(right),
|
200
|
+
where?(where),
|
201
|
+
group?(group),
|
202
|
+
order?(order),
|
203
|
+
limit?(limit, offset),
|
204
|
+
].compact.join(' ')
|
211
205
|
end
|
212
206
|
|
213
207
|
def insert_into(table_name, *rows)
|
214
|
-
raw
|
215
|
-
|
216
|
-
|
217
|
-
|
208
|
+
raw [
|
209
|
+
"INSERT INTO #{name(table_name)} (#{names(*rows.first.keys)})",
|
210
|
+
"VALUES #{list(rows.map { |r| "(#{values(*r.values)})" })}",
|
211
|
+
].join(' ')
|
218
212
|
end
|
219
213
|
|
220
214
|
def update(table_name, set: nil, where: nil, inner: nil, left: nil, right: nil)
|
221
215
|
raise ArgumentError if set.nil?
|
222
216
|
|
223
|
-
raw
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
217
|
+
raw [
|
218
|
+
"UPDATE #{name(table_name)}",
|
219
|
+
"SET #{assign_clause(set)}",
|
220
|
+
inner?(inner),
|
221
|
+
left?(left),
|
222
|
+
right?(right),
|
223
|
+
where?(where),
|
224
|
+
].compact.join(' ')
|
231
225
|
end
|
232
226
|
|
233
227
|
def delete_from(table_name, where: nil, inner: nil, left: nil, right: nil)
|
234
|
-
raw
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
228
|
+
raw [
|
229
|
+
"DELETE FROM #{name(table_name)}",
|
230
|
+
inner?(inner),
|
231
|
+
left?(left),
|
232
|
+
right?(right),
|
233
|
+
where?(where),
|
234
|
+
].join(' ')
|
241
235
|
end
|
242
236
|
|
243
237
|
def truncate(table_name)
|
244
|
-
raw
|
245
|
-
TRUNCATE #{name(table_name)}
|
246
|
-
SQL
|
238
|
+
raw "TRUNCATE #{name(table_name)}"
|
247
239
|
end
|
248
240
|
|
249
241
|
## Functions
|
@@ -300,7 +292,10 @@ module Rebel
|
|
300
292
|
end
|
301
293
|
|
302
294
|
def escape_str(str)
|
303
|
-
str.
|
295
|
+
str.dup.tap do |s|
|
296
|
+
s.gsub!('\\') { @escaped_string_backslash } if @escaped_string_backslash
|
297
|
+
s.gsub!(@string_quote) { @escaped_string_quote }
|
298
|
+
end
|
304
299
|
end
|
305
300
|
|
306
301
|
def value(v)
|
@@ -398,6 +393,7 @@ module Rebel
|
|
398
393
|
@identifier_quote = options[:identifier_quote] || '"'
|
399
394
|
@string_quote = options[:string_quote] || "'"
|
400
395
|
@escaped_string_quote = options[:escaped_string_quote] || "''"
|
396
|
+
@escaped_string_backslash = options[:escaped_string_backslash]
|
401
397
|
@true_literal = options[:true_literal] || 'TRUE'
|
402
398
|
@false_literal = options[:false_literal] || 'FALSE'
|
403
399
|
|
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.7.
|
4
|
+
version: 0.7.1
|
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-
|
11
|
+
date: 2017-11-23 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
|