rebel 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rebel/sql.rb +38 -42
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f16218bb6a1d9a787e819c1443820e5b43ea0add
4
- data.tar.gz: 69b62d3801ac06156ad5ac356234550a7541fc3a
3
+ metadata.gz: 32fd955629a7dbd8738111e47395bbe7cd007792
4
+ data.tar.gz: a1c33efb78711424dfcef3b13c2bf0e775138cdb
5
5
  SHA512:
6
- metadata.gz: 66f5c629576b76c444e65132f910185b36f1386b251a9dfbd832dd5e78cc5c67318252175c4535bcc9c5da659ad79df0e1b25499c2fa300f103583b419a4865e
7
- data.tar.gz: 9311d2677d3c2129b3bb2555b81e0d32359b8ffe42988165d1828a47be954c837fc515ab38a231d079213618f10d39911b2ec4934a22e01589a6f9db774b10be
6
+ metadata.gz: db54aa215e1d4c7e748d1ed04b898129304c8b668966fd32bd31f09374368782f1fbe9ffd249ce9deabe15ee079bcbc54badd3daddb19e410019301ef48a32e9
7
+ data.tar.gz: 3d230eac6c296658d998b627910b69039e735abb9ca2da56cc665ec98e6e9a61f6f8e73a9b50cb031138c1e2d85235faa89462c25d30568dd3e18b2bc400ea93
@@ -183,67 +183,59 @@ module Rebel
183
183
  end
184
184
 
185
185
  def create_table(table_name, desc)
186
- raw <<-SQL
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 <<-SQL
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 <<-SQL
201
- SELECT #{distinct ? "DISTINCT #{names(*distinct)}" : names(*fields)}
202
- #{from?(from)}
203
- #{inner?(inner)}
204
- #{left?(left)}
205
- #{right?(right)}
206
- #{where?(where)}
207
- #{group?(group)}
208
- #{order?(order)}
209
- #{limit?(limit, offset)}
210
- SQL
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 <<-SQL
215
- INSERT INTO #{name(table_name)} (#{names(*rows.first.keys)})
216
- VALUES #{list(rows.map { |r| "(#{values(*r.values)})" })}
217
- SQL
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 <<-SQL
224
- UPDATE #{name(table_name)}
225
- SET #{assign_clause(set)}
226
- #{inner?(inner)}
227
- #{left?(left)}
228
- #{right?(right)}
229
- #{where?(where)}
230
- SQL
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 <<-SQL
235
- DELETE FROM #{name(table_name)}
236
- #{inner?(inner)}
237
- #{left?(left)}
238
- #{right?(right)}
239
- #{where?(where)}
240
- SQL
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 <<-SQL
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.gsub(@string_quote, @escaped_string_quote)
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.0
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-22 00:00:00.000000000 Z
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