fast_inserter 0.1.5 → 0.1.6

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: 120b53eb90d8eef25a9d1f3340b36f4256d9ddca
4
- data.tar.gz: aea33ef6b99f3707b2276785cc5add4d74522020
3
+ metadata.gz: fe09e32230a3dc433d82f2afe7329cfe6388c46d
4
+ data.tar.gz: ea29978534d0cb33c67baafa43fbcd1f8d02735a
5
5
  SHA512:
6
- metadata.gz: e47da657ffab5623bae32686880e916f507b49bd9a33067be2c80ee1131bf269430dc7a2a670045acd478d5a0a16f9d7c1afd971fc1aace6b96db19b89a7d102
7
- data.tar.gz: b694592a8c016b52f39993cd3695316d383868f6cf267b84f50682e4eab662ab5f123a0b041ef1f3759b9d7c620593cb9fb83a98dd7e23c2cbc63bf658779780
6
+ metadata.gz: 03556b9df683ce5c6bce7797af5d6754a001167aeae82bd4edc43b2ed2eb0fc21a23c15f32fb740a1fe884a846660ccebda1cc514dd1c048fc6b619b0470ca61
7
+ data.tar.gz: 389035369e1874a8f522a0c5dbd0be6ddc6e9f16dbf6088101021e05def715d5c204dc49dacb278e8405f4a328c72a7739c472bd3698ada9d233140ed826c0a2
@@ -3,17 +3,15 @@ sudo: required
3
3
  notifications:
4
4
  email: false
5
5
  rvm:
6
- - 2.2.4
7
6
  - 2.3.0
7
+ - 2.4.4
8
+ - 2.5.1
8
9
  - ruby-head
9
10
  env:
10
11
  matrix:
11
12
  - DB=pg
12
13
  - DB=mysql
13
14
  - DB=sqlite
14
- before_install:
15
- # Sqlite set up involves installing a more modern version which we move into a script.
16
- - sh -c "if [ '$DB' = 'sqlite' ]; then ./ci/install_modern_sqlite.sh; fi;"
17
15
  before_script:
18
16
  # PG and mysql is simpler.
19
17
  - sh -c "if [ '$DB' = 'pg' ]; then psql -c 'DROP DATABASE IF EXISTS fast_inserter;' -U postgres; fi"
@@ -1,3 +1,15 @@
1
+ ## Unreleased ##
2
+
3
+ * Remove support for Ruby 2.2. Add support for Ruby 2.4 and 2.5.
4
+
5
+ *Scott Ringwelski*
6
+
7
+ ## 0.1.5 (January 9, 2017) ##
8
+
9
+ * Support multiple variable columns
10
+
11
+ *Josh Warfield*
12
+
1
13
  ## 0.1.4 (September 19, 2016) ##
2
14
 
3
15
  * Improve performance when checking for existing records.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # FastInserter
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/fast_inserter.svg)](https://badge.fury.io/rb/fast_inserter)
4
- [![Build Status](https://travis-ci.org/strydercorp/fast_inserter.svg?branch=master)](https://travis-ci.org/strydercorp/fast_inserter)
4
+ [![Build Status](https://travis-ci.org/joinhandshake/fast_inserter.svg?branch=master)](https://travis-ci.org/joinhandshake/fast_inserter)
5
5
 
6
6
  Use raw SQL to insert database records in bulk, fast. Supports uniqueness constraints, timestamps, and checking for existing records.
7
7
 
@@ -52,7 +52,7 @@ params = {
52
52
  timestamps: true,
53
53
  unique: true,
54
54
  check_for_existing: true,
55
- group_size: 10_000
55
+ group_size: 2_000
56
56
  },
57
57
  variable_column: 'user_id',
58
58
  values: user_ids
@@ -89,7 +89,7 @@ Queries the table for any values which already exist and removes them from the v
89
89
 
90
90
  ### group_size
91
91
 
92
- Insertions will be broken up into batches. This specifies the number of records you want to insert per batch. Default is 10,000.
92
+ Insertions will be broken up into batches. This specifies the number of records you want to insert per batch. Default is 2,000.
93
93
 
94
94
  ### variable_column
95
95
 
@@ -116,7 +116,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
116
116
 
117
117
  ## Contributing
118
118
 
119
- Bug reports and pull requests are welcome on GitHub at https://github.com/strydercorp/fast_inserter. All code must run on sqlite, pg, and mysql (tests are set up CI already).
119
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joinhandshake/fast_inserter. All code must run on sqlite, pg, and mysql (tests are set up CI already).
120
120
 
121
121
 
122
122
  ## License
@@ -6,8 +6,8 @@ require 'fast_inserter/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "fast_inserter"
8
8
  spec.version = FastInserter::VERSION
9
- spec.authors = ["Scott Ringwelski", "Brandon Gafford", "Jordon Dornbos", "Matt Hickman"]
10
- spec.email = ["scott@joinhandshake.com", "brandon@joinhandshake.com", "jordon@joinhandshake.com", "matt@joinhandshake.com"]
9
+ spec.authors = ["Scott Ringwelski", "Brandon Gafford", "Jordon Dornbos", "Matt Hickman", "Josh Warfield"]
10
+ spec.email = ["scott@joinhandshake.com", "brandon@joinhandshake.com", "jordon@joinhandshake.com", "matt@joinhandshake.com", "josh@joinhandshake.com"]
11
11
 
12
12
  spec.summary = %q{Quickly insert database records in bulk}
13
13
  spec.description = %q{Use raw SQL to insert database records in bulk. Supports uniqueness constraints, timestamps, and checking for existing records.}
@@ -82,7 +82,7 @@ module FastInserter
82
82
  def fast_insert_group(group)
83
83
  if @options[:check_for_existing]
84
84
  ActiveRecord::Base.transaction do
85
- non_existing_values = group.map { |values| values.map(&:to_s) } - existing_values(group)
85
+ non_existing_values = stringify_values(group) - existing_values(group)
86
86
  sql_string = insertion_sql_for_group(non_existing_values)
87
87
  ActiveRecord::Base.connection.execute(sql_string) unless non_existing_values.empty?
88
88
  end
@@ -100,20 +100,24 @@ module FastInserter
100
100
  # of result from 'execute(sql)'. Potential classes for 'result' is Array (sqlite), Mysql2::Result (mysql2), PG::Result (pg). Each
101
101
  # result can be enumerated into a list of arrays (mysql) or list of hashes (sqlite, pg)
102
102
  results = ActiveRecord::Base.connection.execute(sql)
103
- existing_values = results.to_a.map do |result|
104
- if result.is_a?(Hash)
105
- @variable_columns.map { |col| result[col] }.map(&:to_s)
106
- elsif result.is_a?(Array)
107
- result.map(&:to_s)
108
- end
109
- end
103
+ existing_values = stringify_values(results)
110
104
 
111
105
  # Rather than a giant IN query in the sql statement (which can be bad for database performance),
112
106
  # do the filtering of relevant values here in a ruby select.
113
- group_of_values_strings = group_of_values.map { |values| values.map(&:to_s) }
107
+ group_of_values_strings = stringify_values(group_of_values)
114
108
  existing_values & group_of_values_strings
115
109
  end
116
110
 
111
+ def stringify_values(results)
112
+ results.to_a.map do |result|
113
+ if result.is_a?(Hash)
114
+ @variable_columns.map { |col| ActiveRecord::Base.connection.type_cast(result[col], column_definitions[col]) }
115
+ elsif result.is_a?(Array)
116
+ result.map.with_index { |val, i| ActiveRecord::Base.connection.type_cast(val, column_definitions[@variable_columns[i]]) }
117
+ end
118
+ end
119
+ end
120
+
117
121
  def existing_values_static_columns
118
122
  @static_columns.map do |key, value|
119
123
  if value.nil?
@@ -164,5 +168,13 @@ module FastInserter
164
168
 
165
169
  rv.join(', ')
166
170
  end
171
+
172
+ def column_definitions
173
+ @column_definitions ||= begin
174
+ ActiveRecord::Base.connection.columns(@table_name).reduce({}) do |memo, column|
175
+ memo.merge!(column.name => column)
176
+ end
177
+ end
178
+ end
167
179
  end
168
180
  end
@@ -1,3 +1,3 @@
1
1
  module FastInserter
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_inserter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Ringwelski
8
8
  - Brandon Gafford
9
9
  - Jordon Dornbos
10
10
  - Matt Hickman
11
+ - Josh Warfield
11
12
  autorequire:
12
13
  bindir: exe
13
14
  cert_chain: []
14
- date: 2017-01-09 00:00:00.000000000 Z
15
+ date: 2018-07-03 00:00:00.000000000 Z
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: activerecord
@@ -104,6 +105,7 @@ email:
104
105
  - brandon@joinhandshake.com
105
106
  - jordon@joinhandshake.com
106
107
  - matt@joinhandshake.com
108
+ - josh@joinhandshake.com
107
109
  executables: []
108
110
  extensions: []
109
111
  extra_rdoc_files: []
@@ -119,7 +121,6 @@ files:
119
121
  - Rakefile
120
122
  - bin/console
121
123
  - bin/setup
122
- - ci/install_modern_sqlite.sh
123
124
  - fast_inserter.gemspec
124
125
  - lib/fast_inserter.rb
125
126
  - lib/fast_inserter/fast_inserter_base.rb
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e # halt script on error
3
-
4
- sudo apt-get autoremove sqlite3
5
- sudo apt-get install python-software-properties
6
- sudo apt-add-repository -y ppa:travis-ci/sqlite3
7
- sudo apt-get -y update
8
- sudo apt-cache show sqlite3
9
- sudo apt-get install sqlite3=3.7.15.1-1~travis1
10
- sudo sqlite3 -version
11
- sudo psql --version
12
- sudo mysql --version
13
- gem update bundler