multi_insert 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cef8e229718dc7e2ab4056de9c5acf7727753cf5
4
- data.tar.gz: b21f08bf1fed8b841ea928efda408d5a39ee44e3
3
+ metadata.gz: c75ea9caa10a1bc32e4351f25612fc7008916d29
4
+ data.tar.gz: 84f9e785d7dace05d0cc89f5104eadba95815153
5
5
  SHA512:
6
- metadata.gz: 4718827cdc18dfc58bcae9d4f6e3ed670867ed2e30dbdf056c7c6be1fcfdcbb45baa51d6898b7c822a51eb1bb445c2b1cb469c028af463a2de66c370fc2ef721
7
- data.tar.gz: 7728c0c7f4cff1061c49ce95c433a5743cbf9ec5520e715551bb3d97945e00e3a3ec822e7a0b9a9eeefd8c8362996c8fd724faa37829b45488172bd6c8519ca6
6
+ metadata.gz: 9379b6694ca7040cf7b8df04d2f182c228d5589edccd15774c8e907ac45fef607cd042ff6e184a2ec6e425c82356ea4e4a8c6ff2a7c7475ed6ec1cd7c98f5215
7
+ data.tar.gz: 9bb296fee356a6134ee71c2d0502654685e9f07c423f4426a8509c58265d42b6d0fc2f01096b4605ba15b230734b61e8d0833756abe224fb1a448cb7a5d7ed2a
@@ -2,7 +2,7 @@ require 'active_record'
2
2
  require 'multi_insert/query'
3
3
 
4
4
  class ActiveRecord::Base
5
- def self.multi_insert(columns, values)
6
- ::MultiInsert::Query.new(table_name, columns, values)
5
+ def self.multi_insert(columns, values, opts = {})
6
+ ::MultiInsert::Query.new(table_name, columns, values, opts)
7
7
  end
8
8
  end
@@ -3,9 +3,9 @@ require 'multi_insert/query_builder'
3
3
 
4
4
  module MultiInsert
5
5
  class Query
6
- def initialize(table, columns, values)
6
+ def initialize(table, columns, values, opts = {})
7
7
  @table = table.to_sym
8
- @sql_insert = ::MultiInsert::QueryBuilder.insert(table, columns, values)
8
+ @sql_insert = ::MultiInsert::QueryBuilder.insert(table, columns, values, opts = {})
9
9
  end
10
10
 
11
11
  def returning(columns)
@@ -2,19 +2,25 @@ require 'active_record'
2
2
 
3
3
  module MultiInsert
4
4
  module QueryBuilder
5
- def self.insert(table, columns, values)
5
+ def self.insert(table, columns, values, opts = {})
6
6
  ar = ActiveRecord::Base.connection
7
7
 
8
- now = Time.now.to_s(:db)
8
+ options = {time: true}
9
+ options.merge!(opts)
10
+
11
+ now = Time.now.to_s(:db) if options[:time]
9
12
  table = ar.quote_table_name(table.to_s)
10
13
 
11
14
  # Format columns
12
- columns = columns + [:created_at, :updated_at]
15
+ columns = columns + [:created_at, :updated_at] if options[:time]
13
16
  columns = columns.map!{|c| ar.quote_column_name(c.to_s)}
14
17
  columns = join_params(columns)
15
18
 
16
19
  # Format values
17
- values = values.map{|v| join_params((v + [now, now]).map{|vv| ar.quote(vv.to_s)})}.join(',')
20
+ if options[:time]
21
+ values = values.map{|v| v + [now, now]}
22
+ end
23
+ values = values.map{|v| join_params(v.map{|vv| ar.quote(vv.to_s)})}.join(',')
18
24
 
19
25
  "INSERT INTO #{table} #{columns} VALUES #{values}"
20
26
  end
@@ -1,3 +1,3 @@
1
1
  module MultiInsert
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_insert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nax