fast_inserter 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/CHANGELOG.md +7 -0
- data/README.md +5 -3
- data/fast_inserter.gemspec +3 -3
- data/lib/fast_inserter/fast_inserter_base.rb +6 -2
- data/lib/fast_inserter/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11cad819cb2f00ec07b452cc3e85c3c20ce074de
|
4
|
+
data.tar.gz: 726d13fd3d3b64419a55bb9898e0629e985b6ca1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aa21e548ff8899ea7c63f665637072b3c3af3d4d68dc3a45bfb5af72bbb26a758098be11c84afbc9064ad30f185ed4970600545e52df0baca9fd753208212a8
|
7
|
+
data.tar.gz: 11ecd4447149a187c26bf356fb045292d91ce033a6b875ed5cf35a49cf4dc90d2305e306304067d9c9a07106274212a25c66d47ca95c616f10f47dd0cd9f7601
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/fast_inserter.svg)](https://badge.fury.io/rb/fast_inserter)
|
4
4
|
[![Build Status](https://travis-ci.org/strydercorp/fast_inserter.svg?branch=master)](https://travis-ci.org/strydercorp/fast_inserter)
|
5
5
|
|
6
|
-
Use raw SQL to insert database records in bulk. Supports uniqueness constraints, timestamps, and checking for existing records.
|
6
|
+
Use raw SQL to insert database records in bulk, fast. Supports uniqueness constraints, timestamps, and checking for existing records.
|
7
7
|
|
8
|
-
The motivation for this library from the fact that rails does validations on each and every inserted record in the join table. And, even if you pass validate: false, it still loads each record and inserts one by one. This
|
8
|
+
The motivation for this library comes from the fact that rails does validations on each and every inserted record in the join table. And, even if you pass validate: false, it still loads each record and inserts one by one. This is all good, but also means inserting a large number (thousands) of records is slow.
|
9
9
|
|
10
10
|
This library skips active record altogether and uses raw sql to insert records. However, using raw sql goes around all your business logic, so we provide ways to still have niceties like uniqueness constraints and timestamps.
|
11
11
|
|
@@ -31,7 +31,9 @@ Or install it yourself as:
|
|
31
31
|
|
32
32
|
## Usage
|
33
33
|
|
34
|
-
|
34
|
+
*We wrote a longer post about this gem at https://joinhandshake.com/engineering/2016/01/26/quickly-inserting-thousands-of-records-in-rails.html*
|
35
|
+
|
36
|
+
In most cases, you probably don't want to use this library and instead should use active record. However, should you need to use this library, usage instructions are below.
|
35
37
|
|
36
38
|
A basic usage for inserting multiple 'MassEmailsUser' records:
|
37
39
|
|
data/fast_inserter.gemspec
CHANGED
@@ -6,12 +6,12 @@ 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"]
|
10
|
-
spec.email = ["scott@joinhandshake.com", "brandon@joinhandshake.com", "jordon@joinhandshake.com"]
|
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"]
|
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.}
|
14
|
-
spec.homepage = "https://github.com/strydercorp/fast_inserter
|
14
|
+
spec.homepage = "https://github.com/strydercorp/fast_inserter"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
@@ -110,8 +110,12 @@ module FastInserter
|
|
110
110
|
|
111
111
|
def existing_values_static_columns
|
112
112
|
@static_columns.map do |key, value|
|
113
|
-
|
114
|
-
|
113
|
+
if value.nil?
|
114
|
+
"#{key} IS NULL"
|
115
|
+
else
|
116
|
+
sanitized_value = ActiveRecord::Base.send(:sanitize_sql_array, ["?", value])
|
117
|
+
"#{key} = #{sanitized_value}"
|
118
|
+
end
|
115
119
|
end.join(' AND ')
|
116
120
|
end
|
117
121
|
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_inserter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Ringwelski
|
8
8
|
- Brandon Gafford
|
9
9
|
- Jordon Dornbos
|
10
|
+
- Matt Hickman
|
10
11
|
autorequire:
|
11
12
|
bindir: exe
|
12
13
|
cert_chain: []
|
13
|
-
date: 2016-
|
14
|
+
date: 2016-08-11 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: activerecord
|
@@ -102,6 +103,7 @@ email:
|
|
102
103
|
- scott@joinhandshake.com
|
103
104
|
- brandon@joinhandshake.com
|
104
105
|
- jordon@joinhandshake.com
|
106
|
+
- matt@joinhandshake.com
|
105
107
|
executables: []
|
106
108
|
extensions: []
|
107
109
|
extra_rdoc_files: []
|
@@ -122,7 +124,7 @@ files:
|
|
122
124
|
- lib/fast_inserter.rb
|
123
125
|
- lib/fast_inserter/fast_inserter_base.rb
|
124
126
|
- lib/fast_inserter/version.rb
|
125
|
-
homepage: https://github.com/strydercorp/fast_inserter
|
127
|
+
homepage: https://github.com/strydercorp/fast_inserter
|
126
128
|
licenses:
|
127
129
|
- MIT
|
128
130
|
metadata: {}
|