sugoi_bulk_insert 0.1.0
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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sugoi_bulk_insert.rb +53 -0
- data/lib/sugoi_bulk_insert/version.rb +3 -0
- data/sugoi_bulk_insert.gemspec +27 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f53f0cdd970bbd2ba2a65b79dabb6ef7b837d141
|
4
|
+
data.tar.gz: e69b45fea1094266b56a566670dab8dc05b11246
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c27e539110043843261fdf4b639b339aeed009fa889de0dec75e6ed6aff6e581d831bd0621f2f79d984e8dd1d5cffa3d37ab9015dd3e0c6708ca7984ee7bd72f
|
7
|
+
data.tar.gz: 06f3c14e3db99624c606e48c280e11455238168e630f1a7bef9aac411979fafcdec646aad5e8604276909fd6a0afc28ba93a5bf048ba5373bf228bdc79f689d3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# SugoiBulkInsert
|
2
|
+
|
3
|
+
## Requirements
|
4
|
+
|
5
|
+
* ruby 2.2.0 later
|
6
|
+
* MySQL
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'sugoi_bulk_insert'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install sugoi_bulk_insert
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
```sql
|
26
|
+
mysql> show create table comments;
|
27
|
+
+----------+--------------------------------------+
|
28
|
+
| Table | Create Table |
|
29
|
+
+----------+--------------------------------------+
|
30
|
+
| comments | CREATE TABLE `comments` (
|
31
|
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
32
|
+
`commentable_type` varchar(255) DEFAULT NULL,
|
33
|
+
`commentable_id` int(11) DEFAULT NULL,
|
34
|
+
`title` varchar(255) DEFAULT NULL,
|
35
|
+
`body` text,
|
36
|
+
PRIMARY KEY (`id`)
|
37
|
+
) ENGINE=InnoDB AUTO_INCREMENT=480010 DEFAULT CHARSET=utf8 |
|
38
|
+
+----------+--------------------------------------+
|
39
|
+
1 row in set (0.00 sec)
|
40
|
+
```
|
41
|
+
```ruby
|
42
|
+
b = SugoiBulkInsert.new(table_name: "comments", count: 300) do |x|
|
43
|
+
x.column :commentable_type, %w(AAA VVV CCC GGG)
|
44
|
+
x.column :commentable_id, 1..300000
|
45
|
+
x.column :title, 'aaaa'
|
46
|
+
x.column :body, 'aaaa'
|
47
|
+
end
|
48
|
+
b.to_sql # => display insert sql
|
49
|
+
b.fire # => insert!
|
50
|
+
```
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sugoi_bulk_insert.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sugoi_bulk_insert"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "sugoi_bulk_insert/version"
|
2
|
+
|
3
|
+
module SugoiBulkInsert
|
4
|
+
def self.new(*args, &block)
|
5
|
+
Builder.new(*args, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
class Builder
|
9
|
+
def initialize(table_name: , count: 1000)
|
10
|
+
@table_name = table_name
|
11
|
+
@count = count
|
12
|
+
@table_info = {}
|
13
|
+
yield(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def column(name, value)
|
17
|
+
@table_info[name] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def fire
|
21
|
+
ActiveRecord::Base.connection.execute(to_sql)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_sql
|
25
|
+
"INSERT INTO `#{@table_name}` (#{columns}) VALUES #{values}"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def columns
|
31
|
+
@table_info.keys.map { |x| "`#{x}`" }.join(',')
|
32
|
+
end
|
33
|
+
|
34
|
+
def values
|
35
|
+
list = []
|
36
|
+
@count.times do
|
37
|
+
value = @table_info.values.map { |x|
|
38
|
+
y = case x
|
39
|
+
when Array
|
40
|
+
x.sample
|
41
|
+
when Range
|
42
|
+
Random.rand(x)
|
43
|
+
else
|
44
|
+
x
|
45
|
+
end
|
46
|
+
y.is_a?(Fixnum) ? y : "'#{y}'"
|
47
|
+
}
|
48
|
+
list << "(#{value.join(',')})"
|
49
|
+
end
|
50
|
+
list.join(',')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sugoi_bulk_insert/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sugoi_bulk_insert"
|
8
|
+
spec.version = SugoiBulkInsert::VERSION
|
9
|
+
spec.authors = ["jiikko"]
|
10
|
+
spec.email = ["n905i.1214@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{generate bulk insert sql.}
|
13
|
+
spec.description = %q{generate bulk insert without ActiveRecord.}
|
14
|
+
spec.homepage = "https://github.com/jiikko/sugoi_bulk_insert"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "activerecord"
|
26
|
+
spec.add_development_dependency "mysql2"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sugoi_bulk_insert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jiikko
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mysql2
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: generate bulk insert without ActiveRecord.
|
98
|
+
email:
|
99
|
+
- n905i.1214@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- lib/sugoi_bulk_insert.rb
|
113
|
+
- lib/sugoi_bulk_insert/version.rb
|
114
|
+
- sugoi_bulk_insert.gemspec
|
115
|
+
homepage: https://github.com/jiikko/sugoi_bulk_insert
|
116
|
+
licenses: []
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.5.1
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: generate bulk insert sql.
|
138
|
+
test_files: []
|