mass_insert 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +2 -0
  3. data/.travis.yml +12 -10
  4. data/Gemfile +9 -8
  5. data/LICENSE.txt +1 -1
  6. data/README.md +34 -78
  7. data/Rakefile +19 -24
  8. data/lib/mass_insert/adapters/abstract_adapter.rb +54 -0
  9. data/lib/mass_insert/adapters/mysql2_adapter.rb +5 -0
  10. data/lib/mass_insert/adapters/postgresql_adapter.rb +5 -0
  11. data/lib/mass_insert/adapters/sqlite3_adapter.rb +5 -0
  12. data/lib/mass_insert/base.rb +3 -84
  13. data/lib/mass_insert/builder.rb +8 -0
  14. data/lib/mass_insert/executer.rb +2 -6
  15. data/lib/mass_insert/process.rb +14 -14
  16. data/lib/mass_insert/utilities.rb +25 -0
  17. data/lib/mass_insert/version.rb +1 -1
  18. data/lib/mass_insert.rb +9 -5
  19. data/mass_insert.gemspec +10 -10
  20. data/test/adapters/mysql2/example_test.rb +3 -0
  21. data/test/adapters/postgresql/example_test.rb +3 -0
  22. data/test/adapters/sqlite3/example_test.rb +3 -0
  23. data/test/database.yml.example +18 -0
  24. data/test/models/user.rb +2 -0
  25. data/test/schema.rb +11 -0
  26. data/test/support/adapters/mysql2.rb +1 -0
  27. data/test/support/adapters/postgresql.rb +1 -0
  28. data/test/support/adapters/sqlite3.rb +1 -0
  29. data/test/support/shared_examples.rb +57 -0
  30. data/test/test_helper.rb +20 -0
  31. metadata +42 -188
  32. data/.rvmrc +0 -62
  33. data/lib/mass_insert/builder/adapters/adapter.rb +0 -52
  34. data/lib/mass_insert/builder/adapters/helpers/abstract_query.rb +0 -52
  35. data/lib/mass_insert/builder/adapters/helpers/column_value.rb +0 -90
  36. data/lib/mass_insert/builder/adapters/mysql2_adapter.rb +0 -7
  37. data/lib/mass_insert/builder/adapters/postgresql_adapter.rb +0 -7
  38. data/lib/mass_insert/builder/adapters/sqlite3_adapter.rb +0 -27
  39. data/lib/mass_insert/builder/adapters/sqlserver_adapter.rb +0 -20
  40. data/lib/mass_insert/builder/adapters.rb +0 -16
  41. data/lib/mass_insert/builder/base.rb +0 -28
  42. data/lib/mass_insert/builder/utilities.rb +0 -13
  43. data/lib/mass_insert/result.rb +0 -33
  44. data/spec/adapters/column_types/binary_spec.rb +0 -64
  45. data/spec/adapters/column_types/boolean_spec.rb +0 -48
  46. data/spec/adapters/column_types/date_spec.rb +0 -14
  47. data/spec/adapters/column_types/datetime_spec.rb +0 -14
  48. data/spec/adapters/column_types/decimal_spec.rb +0 -59
  49. data/spec/adapters/column_types/integer_spec.rb +0 -59
  50. data/spec/adapters/column_types/string_spec.rb +0 -46
  51. data/spec/adapters/column_types/time_spec.rb +0 -14
  52. data/spec/adapters/model_spec.rb +0 -83
  53. data/spec/dummy/.gitignore +0 -15
  54. data/spec/dummy/Gemfile +0 -40
  55. data/spec/dummy/README.rdoc +0 -261
  56. data/spec/dummy/Rakefile +0 -7
  57. data/spec/dummy/app/assets/images/rails.png +0 -0
  58. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  59. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  60. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  61. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  62. data/spec/dummy/app/mailers/.gitkeep +0 -0
  63. data/spec/dummy/app/models/.gitkeep +0 -0
  64. data/spec/dummy/app/models/user.rb +0 -3
  65. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  66. data/spec/dummy/config/application.rb +0 -68
  67. data/spec/dummy/config/boot.rb +0 -6
  68. data/spec/dummy/config/database.yml +0 -49
  69. data/spec/dummy/config/environment.rb +0 -5
  70. data/spec/dummy/config/environments/development.rb +0 -37
  71. data/spec/dummy/config/environments/mysql2.rb +0 -37
  72. data/spec/dummy/config/environments/postgresql.rb +0 -37
  73. data/spec/dummy/config/environments/production.rb +0 -67
  74. data/spec/dummy/config/environments/sqlite3.rb +0 -37
  75. data/spec/dummy/config/environments/test.rb +0 -37
  76. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  77. data/spec/dummy/config/initializers/inflections.rb +0 -15
  78. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  79. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  80. data/spec/dummy/config/initializers/session_store.rb +0 -8
  81. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  82. data/spec/dummy/config/locales/en.yml +0 -5
  83. data/spec/dummy/config/routes.rb +0 -58
  84. data/spec/dummy/config.ru +0 -4
  85. data/spec/dummy/db/migrate/20130412154541_create_users.rb +0 -16
  86. data/spec/dummy/db/schema.rb +0 -29
  87. data/spec/dummy/db/seeds.rb +0 -7
  88. data/spec/dummy/lib/assets/.gitkeep +0 -0
  89. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  90. data/spec/dummy/log/.gitkeep +0 -0
  91. data/spec/dummy/public/404.html +0 -26
  92. data/spec/dummy/public/422.html +0 -26
  93. data/spec/dummy/public/500.html +0 -25
  94. data/spec/dummy/public/favicon.ico +0 -0
  95. data/spec/dummy/public/index.html +0 -241
  96. data/spec/dummy/public/robots.txt +0 -5
  97. data/spec/dummy/script/rails +0 -6
  98. data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
  99. data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  100. data/spec/dummy/vendor/plugins/.gitkeep +0 -0
  101. data/spec/lib/mass_insert/base_spec.rb +0 -40
  102. data/spec/lib/mass_insert/builder/adapters/adapter_spec.rb +0 -116
  103. data/spec/lib/mass_insert/builder/adapters/helpers/abstract_query_spec.rb +0 -130
  104. data/spec/lib/mass_insert/builder/adapters/helpers/column_value_spec.rb +0 -222
  105. data/spec/lib/mass_insert/builder/adapters/mysql_adapter_spec.rb +0 -9
  106. data/spec/lib/mass_insert/builder/adapters/postgresql_adapter_spec.rb +0 -9
  107. data/spec/lib/mass_insert/builder/adapters/sqlite3_adapter_spec.rb +0 -52
  108. data/spec/lib/mass_insert/builder/adapters/sqlserver_adapter_spec.rb +0 -32
  109. data/spec/lib/mass_insert/builder/adapters_spec.rb +0 -31
  110. data/spec/lib/mass_insert/builder/base_spec.rb +0 -28
  111. data/spec/lib/mass_insert/builder/utilities_spec.rb +0 -11
  112. data/spec/lib/mass_insert/executer_spec.rb +0 -33
  113. data/spec/lib/mass_insert/process_spec.rb +0 -58
  114. data/spec/lib/mass_insert/result_spec.rb +0 -45
  115. data/spec/lib/mass_insert_spec.rb +0 -35
  116. data/spec/spec_helper.rb +0 -15
  117. data/spec/support/mass_insert_support.rb +0 -12
@@ -0,0 +1,57 @@
1
+ def shared_examples
2
+ describe 'Database Adapters' do
3
+ let(:attributes) do
4
+ {
5
+ name: 'User Name',
6
+ active: true,
7
+ age: 25,
8
+ money: 20.50,
9
+ birth_date: Date.today,
10
+ created_at: DateTime.now,
11
+ updated_at: DateTime.now
12
+ }
13
+ end
14
+
15
+ after :each do
16
+ User.delete_all
17
+ end
18
+
19
+ describe 'Column types' do
20
+ def setup
21
+ User.mass_insert([attributes])
22
+ end
23
+
24
+ def user
25
+ @user ||= User.last
26
+ end
27
+
28
+ it 'saves values correctly' do
29
+ assert_equal user.name, 'User Name'
30
+ assert_equal user.active, true
31
+ assert_equal user.age, 25
32
+ assert_equal user.money, 20.50
33
+ assert_equal user.birth_date, Date.today
34
+ end
35
+ end
36
+
37
+ describe 'Bulk inseting' do
38
+ def array_of_values_with(size)
39
+ (0...size).map do |i|
40
+ attributes
41
+ end
42
+ end
43
+
44
+ it 'saves 500 records correctly' do
45
+ values = array_of_values_with(500)
46
+ User.mass_insert(values)
47
+ assert_equal User.count, 500
48
+ end
49
+
50
+ it 'saves 1000 records correctly' do
51
+ values = array_of_values_with(1000)
52
+ User.mass_insert(values)
53
+ assert_equal User.count, 1000
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,20 @@
1
+ require 'minitest/autorun'
2
+ require 'logger'
3
+ require 'active_record'
4
+ require 'mass_insert'
5
+ require 'fileutils'
6
+
7
+ adapter = ENV['DATABASE_ADAPTER'] || 'sqlite3'
8
+
9
+ FileUtils.mkdir_p('tmp')
10
+ FileUtils.mkdir_p('log')
11
+
12
+ ActiveRecord::Base.logger = Logger.new('log/test.log')
13
+ ActiveRecord::Base.logger.level = Logger::DEBUG
14
+ ActiveRecord::Base.configurations['test'] = YAML.load_file(File.dirname(__FILE__) + '/database.yml')[adapter]
15
+ ActiveRecord::Base.establish_connection(:test)
16
+
17
+ require File.dirname(__FILE__) + '/schema.rb'
18
+
19
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each{ |file| require file }
20
+ Dir[File.dirname(__FILE__) + "/models/**/*.rb"].each{ |file| require file }
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mass_insert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Gutiérrez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-30 00:00:00.000000000 Z
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
19
+ version: '3.2'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '3.2'
41
27
  description: This gem aims to provide an easy and faster way to do single database
42
28
  insertions in Rails.
43
29
  email:
@@ -46,105 +32,36 @@ executables: []
46
32
  extensions: []
47
33
  extra_rdoc_files: []
48
34
  files:
49
- - .gitignore
50
- - .rspec
51
- - .rvmrc
52
- - .travis.yml
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".travis.yml"
53
38
  - Gemfile
54
39
  - LICENSE.txt
55
40
  - README.md
56
41
  - Rakefile
57
42
  - lib/mass_insert.rb
43
+ - lib/mass_insert/adapters/abstract_adapter.rb
44
+ - lib/mass_insert/adapters/mysql2_adapter.rb
45
+ - lib/mass_insert/adapters/postgresql_adapter.rb
46
+ - lib/mass_insert/adapters/sqlite3_adapter.rb
58
47
  - lib/mass_insert/base.rb
59
- - lib/mass_insert/builder/adapters.rb
60
- - lib/mass_insert/builder/adapters/adapter.rb
61
- - lib/mass_insert/builder/adapters/helpers/abstract_query.rb
62
- - lib/mass_insert/builder/adapters/helpers/column_value.rb
63
- - lib/mass_insert/builder/adapters/mysql2_adapter.rb
64
- - lib/mass_insert/builder/adapters/postgresql_adapter.rb
65
- - lib/mass_insert/builder/adapters/sqlite3_adapter.rb
66
- - lib/mass_insert/builder/adapters/sqlserver_adapter.rb
67
- - lib/mass_insert/builder/base.rb
68
- - lib/mass_insert/builder/utilities.rb
48
+ - lib/mass_insert/builder.rb
69
49
  - lib/mass_insert/executer.rb
70
50
  - lib/mass_insert/process.rb
71
- - lib/mass_insert/result.rb
51
+ - lib/mass_insert/utilities.rb
72
52
  - lib/mass_insert/version.rb
73
53
  - mass_insert.gemspec
74
- - spec/adapters/column_types/binary_spec.rb
75
- - spec/adapters/column_types/boolean_spec.rb
76
- - spec/adapters/column_types/date_spec.rb
77
- - spec/adapters/column_types/datetime_spec.rb
78
- - spec/adapters/column_types/decimal_spec.rb
79
- - spec/adapters/column_types/integer_spec.rb
80
- - spec/adapters/column_types/string_spec.rb
81
- - spec/adapters/column_types/time_spec.rb
82
- - spec/adapters/model_spec.rb
83
- - spec/dummy/.gitignore
84
- - spec/dummy/Gemfile
85
- - spec/dummy/README.rdoc
86
- - spec/dummy/Rakefile
87
- - spec/dummy/app/assets/images/rails.png
88
- - spec/dummy/app/assets/javascripts/application.js
89
- - spec/dummy/app/assets/stylesheets/application.css
90
- - spec/dummy/app/controllers/application_controller.rb
91
- - spec/dummy/app/helpers/application_helper.rb
92
- - spec/dummy/app/mailers/.gitkeep
93
- - spec/dummy/app/models/.gitkeep
94
- - spec/dummy/app/models/user.rb
95
- - spec/dummy/app/views/layouts/application.html.erb
96
- - spec/dummy/config.ru
97
- - spec/dummy/config/application.rb
98
- - spec/dummy/config/boot.rb
99
- - spec/dummy/config/database.yml
100
- - spec/dummy/config/environment.rb
101
- - spec/dummy/config/environments/development.rb
102
- - spec/dummy/config/environments/mysql2.rb
103
- - spec/dummy/config/environments/postgresql.rb
104
- - spec/dummy/config/environments/production.rb
105
- - spec/dummy/config/environments/sqlite3.rb
106
- - spec/dummy/config/environments/test.rb
107
- - spec/dummy/config/initializers/backtrace_silencers.rb
108
- - spec/dummy/config/initializers/inflections.rb
109
- - spec/dummy/config/initializers/mime_types.rb
110
- - spec/dummy/config/initializers/secret_token.rb
111
- - spec/dummy/config/initializers/session_store.rb
112
- - spec/dummy/config/initializers/wrap_parameters.rb
113
- - spec/dummy/config/locales/en.yml
114
- - spec/dummy/config/routes.rb
115
- - spec/dummy/db/migrate/20130412154541_create_users.rb
116
- - spec/dummy/db/schema.rb
117
- - spec/dummy/db/seeds.rb
118
- - spec/dummy/lib/assets/.gitkeep
119
- - spec/dummy/lib/tasks/.gitkeep
120
- - spec/dummy/log/.gitkeep
121
- - spec/dummy/public/404.html
122
- - spec/dummy/public/422.html
123
- - spec/dummy/public/500.html
124
- - spec/dummy/public/favicon.ico
125
- - spec/dummy/public/index.html
126
- - spec/dummy/public/robots.txt
127
- - spec/dummy/script/rails
128
- - spec/dummy/vendor/assets/javascripts/.gitkeep
129
- - spec/dummy/vendor/assets/stylesheets/.gitkeep
130
- - spec/dummy/vendor/plugins/.gitkeep
131
- - spec/lib/mass_insert/base_spec.rb
132
- - spec/lib/mass_insert/builder/adapters/adapter_spec.rb
133
- - spec/lib/mass_insert/builder/adapters/helpers/abstract_query_spec.rb
134
- - spec/lib/mass_insert/builder/adapters/helpers/column_value_spec.rb
135
- - spec/lib/mass_insert/builder/adapters/mysql_adapter_spec.rb
136
- - spec/lib/mass_insert/builder/adapters/postgresql_adapter_spec.rb
137
- - spec/lib/mass_insert/builder/adapters/sqlite3_adapter_spec.rb
138
- - spec/lib/mass_insert/builder/adapters/sqlserver_adapter_spec.rb
139
- - spec/lib/mass_insert/builder/adapters_spec.rb
140
- - spec/lib/mass_insert/builder/base_spec.rb
141
- - spec/lib/mass_insert/builder/utilities_spec.rb
142
- - spec/lib/mass_insert/executer_spec.rb
143
- - spec/lib/mass_insert/process_spec.rb
144
- - spec/lib/mass_insert/result_spec.rb
145
- - spec/lib/mass_insert_spec.rb
146
- - spec/spec_helper.rb
147
- - spec/support/mass_insert_support.rb
54
+ - test/adapters/mysql2/example_test.rb
55
+ - test/adapters/postgresql/example_test.rb
56
+ - test/adapters/sqlite3/example_test.rb
57
+ - test/database.yml.example
58
+ - test/models/user.rb
59
+ - test/schema.rb
60
+ - test/support/adapters/mysql2.rb
61
+ - test/support/adapters/postgresql.rb
62
+ - test/support/adapters/sqlite3.rb
63
+ - test/support/shared_examples.rb
64
+ - test/test_helper.rb
148
65
  homepage: https://github.com/alejandrogutierrez/mass_insert
149
66
  licenses:
150
67
  - MIT
@@ -155,12 +72,12 @@ require_paths:
155
72
  - lib
156
73
  required_ruby_version: !ruby/object:Gem::Requirement
157
74
  requirements:
158
- - - ! '>='
75
+ - - ">="
159
76
  - !ruby/object:Gem::Version
160
- version: '0'
77
+ version: 1.9.3
161
78
  required_rubygems_version: !ruby/object:Gem::Requirement
162
79
  requirements:
163
- - - ! '>='
80
+ - - ">="
164
81
  - !ruby/object:Gem::Version
165
82
  version: '0'
166
83
  requirements: []
@@ -170,77 +87,14 @@ signing_key:
170
87
  specification_version: 4
171
88
  summary: Mass database insertion in Rails
172
89
  test_files:
173
- - spec/adapters/column_types/binary_spec.rb
174
- - spec/adapters/column_types/boolean_spec.rb
175
- - spec/adapters/column_types/date_spec.rb
176
- - spec/adapters/column_types/datetime_spec.rb
177
- - spec/adapters/column_types/decimal_spec.rb
178
- - spec/adapters/column_types/integer_spec.rb
179
- - spec/adapters/column_types/string_spec.rb
180
- - spec/adapters/column_types/time_spec.rb
181
- - spec/adapters/model_spec.rb
182
- - spec/dummy/.gitignore
183
- - spec/dummy/Gemfile
184
- - spec/dummy/README.rdoc
185
- - spec/dummy/Rakefile
186
- - spec/dummy/app/assets/images/rails.png
187
- - spec/dummy/app/assets/javascripts/application.js
188
- - spec/dummy/app/assets/stylesheets/application.css
189
- - spec/dummy/app/controllers/application_controller.rb
190
- - spec/dummy/app/helpers/application_helper.rb
191
- - spec/dummy/app/mailers/.gitkeep
192
- - spec/dummy/app/models/.gitkeep
193
- - spec/dummy/app/models/user.rb
194
- - spec/dummy/app/views/layouts/application.html.erb
195
- - spec/dummy/config.ru
196
- - spec/dummy/config/application.rb
197
- - spec/dummy/config/boot.rb
198
- - spec/dummy/config/database.yml
199
- - spec/dummy/config/environment.rb
200
- - spec/dummy/config/environments/development.rb
201
- - spec/dummy/config/environments/mysql2.rb
202
- - spec/dummy/config/environments/postgresql.rb
203
- - spec/dummy/config/environments/production.rb
204
- - spec/dummy/config/environments/sqlite3.rb
205
- - spec/dummy/config/environments/test.rb
206
- - spec/dummy/config/initializers/backtrace_silencers.rb
207
- - spec/dummy/config/initializers/inflections.rb
208
- - spec/dummy/config/initializers/mime_types.rb
209
- - spec/dummy/config/initializers/secret_token.rb
210
- - spec/dummy/config/initializers/session_store.rb
211
- - spec/dummy/config/initializers/wrap_parameters.rb
212
- - spec/dummy/config/locales/en.yml
213
- - spec/dummy/config/routes.rb
214
- - spec/dummy/db/migrate/20130412154541_create_users.rb
215
- - spec/dummy/db/schema.rb
216
- - spec/dummy/db/seeds.rb
217
- - spec/dummy/lib/assets/.gitkeep
218
- - spec/dummy/lib/tasks/.gitkeep
219
- - spec/dummy/log/.gitkeep
220
- - spec/dummy/public/404.html
221
- - spec/dummy/public/422.html
222
- - spec/dummy/public/500.html
223
- - spec/dummy/public/favicon.ico
224
- - spec/dummy/public/index.html
225
- - spec/dummy/public/robots.txt
226
- - spec/dummy/script/rails
227
- - spec/dummy/vendor/assets/javascripts/.gitkeep
228
- - spec/dummy/vendor/assets/stylesheets/.gitkeep
229
- - spec/dummy/vendor/plugins/.gitkeep
230
- - spec/lib/mass_insert/base_spec.rb
231
- - spec/lib/mass_insert/builder/adapters/adapter_spec.rb
232
- - spec/lib/mass_insert/builder/adapters/helpers/abstract_query_spec.rb
233
- - spec/lib/mass_insert/builder/adapters/helpers/column_value_spec.rb
234
- - spec/lib/mass_insert/builder/adapters/mysql_adapter_spec.rb
235
- - spec/lib/mass_insert/builder/adapters/postgresql_adapter_spec.rb
236
- - spec/lib/mass_insert/builder/adapters/sqlite3_adapter_spec.rb
237
- - spec/lib/mass_insert/builder/adapters/sqlserver_adapter_spec.rb
238
- - spec/lib/mass_insert/builder/adapters_spec.rb
239
- - spec/lib/mass_insert/builder/base_spec.rb
240
- - spec/lib/mass_insert/builder/utilities_spec.rb
241
- - spec/lib/mass_insert/executer_spec.rb
242
- - spec/lib/mass_insert/process_spec.rb
243
- - spec/lib/mass_insert/result_spec.rb
244
- - spec/lib/mass_insert_spec.rb
245
- - spec/spec_helper.rb
246
- - spec/support/mass_insert_support.rb
90
+ - test/adapters/mysql2/example_test.rb
91
+ - test/adapters/postgresql/example_test.rb
92
+ - test/adapters/sqlite3/example_test.rb
93
+ - test/database.yml.example
94
+ - test/models/user.rb
95
+ - test/schema.rb
96
+ - test/support/adapters/mysql2.rb
97
+ - test/support/adapters/postgresql.rb
98
+ - test/support/adapters/sqlite3.rb
99
+ - test/support/shared_examples.rb
100
+ - test/test_helper.rb
data/.rvmrc DELETED
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
- # development environment upon cd'ing into the directory
5
-
6
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
- # Only full ruby name is supported here, for short names use:
8
- # echo "rvm use 1.9.3" > .rvmrc
9
- environment_id="ruby-1.9.3-p484@mass_insert"
10
-
11
- # Uncomment the following lines if you want to verify rvm version per project
12
- # rvmrc_rvm_version="1.25.14 (stable)" # 1.10.1 seems like a safe start
13
- # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
- # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
- # return 1
16
- # }
17
-
18
- # First we attempt to load the desired environment directly from the environment
19
- # file. This is very fast and efficient compared to running through the entire
20
- # CLI and selector. If you want feedback on which environment was used then
21
- # insert the word 'use' after --create as this triggers verbose mode.
22
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
- then
25
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
- for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
- do
28
- if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
- then \. "${__hook}" || true
30
- fi
31
- done
32
- unset __hook
33
- if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
34
- then
35
- if [[ $- == *i* ]] # check for interactive shells
36
- then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
37
- " # show the user the ruby and gemset they are using in green
38
- else printf "%b" "Using: $GEM_HOME
39
- " # don't use colors in non-interactive shells
40
- fi
41
- fi
42
- else
43
- # If the environment file has not yet been created, use the RVM CLI to select.
44
- rvm --create "$environment_id" || {
45
- echo "Failed to create RVM environment '${environment_id}'."
46
- return 1
47
- }
48
- fi
49
-
50
- # If you use bundler, this might be useful to you:
51
- # if [[ -s Gemfile ]] && {
52
- # ! builtin command -v bundle >/dev/null ||
53
- # builtin command -v bundle | GREP_OPTIONS="" \grep $rvm_path/bin/bundle >/dev/null
54
- # }
55
- # then
56
- # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
57
- # gem install bundler
58
- # fi
59
- # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
60
- # then
61
- # bundle install | GREP_OPTIONS="" \grep -vE '^Using|Your bundle is complete'
62
- # fi
@@ -1,52 +0,0 @@
1
- module MassInsert
2
- module Builder
3
- module Adapters
4
- class Adapter
5
- include Helpers::AbstractQuery
6
-
7
- attr_accessor :values, :options
8
-
9
- def initialize values, options
10
- @values = values
11
- @options = options
12
- end
13
-
14
- # Returns the options according to the method that wasn't found.
15
- def method_missing method, *args
16
- @options.has_key?(method) ? @options[method] : super
17
- end
18
-
19
- # Returns an array according to the options with the column names
20
- # that will be included in the queries.
21
- def columns
22
- @columns ||= sanitized_columns
23
- end
24
-
25
- # Prepare array with the column names according to the options.
26
- def sanitized_columns
27
- columns = class_name.column_names
28
- columns.delete(class_name.primary_key) unless primary_key
29
- columns.map(&:to_sym)
30
- end
31
-
32
- # Returns true o false if the database table has timestamp columns.
33
- def timestamp?
34
- columns.include?(:created_at) && columns.include?(:updated_at)
35
- end
36
-
37
- # Returns the timestamp hash to be merge into row values that will
38
- # be saved in the database.
39
- def timestamp_hash
40
- {:created_at => Time.now, :updated_at => Time.now}
41
- end
42
-
43
- # Returns the amount of records to each query. Tries to take the
44
- # each_slice option value or the length of values.
45
- def values_per_insertion
46
- each_slice || @values.count
47
- end
48
-
49
- end
50
- end
51
- end
52
- end
@@ -1,52 +0,0 @@
1
- module MassInsert
2
- module Builder
3
- module Adapters
4
- module Helpers
5
- module AbstractQuery
6
-
7
- # Returns a basic beginning of the query.
8
- def begin_string
9
- "INSERT INTO #{class_name.table_name} "
10
- end
11
-
12
- # Returns a basic part of the query with the columns definition.
13
- def string_columns
14
- "(#{columns.join(", ")}) "
15
- end
16
-
17
- # Returns a basic part of the query with all the records values.
18
- def string_values
19
- "VALUES (#{string_rows_values});"
20
- end
21
-
22
- # Returns all the column values to all the records
23
- def string_rows_values
24
- values.map{ |row| string_single_row_values(row) }.join("), (")
25
- end
26
-
27
- # Returns all the column values to a single record.
28
- def string_single_row_values row
29
- row.merge!(timestamp_hash) if timestamp?
30
- columns.map{ |col| string_single_value(row, col) }.join(", ")
31
- end
32
-
33
- # Returns a single column value. According to the database
34
- # configuration, column type and presence.
35
- def string_single_value row, column
36
- ColumnValue.new(row, column, class_name).build
37
- end
38
-
39
- # Values will be treated in batches according to the values per
40
- # insertion value. It'll generate an array with queries.
41
- def execute
42
- @values.each_slice(values_per_insertion).map do |slice|
43
- @values = slice
44
- "#{begin_string}#{string_columns}#{string_values}"
45
- end
46
- end
47
-
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,90 +0,0 @@
1
- module MassInsert
2
- module Builder
3
- module Adapters
4
- module Helpers
5
- class ColumnValue
6
-
7
- attr_accessor :row, :column, :class_name
8
-
9
- def initialize row, column, class_name
10
- @row = row
11
- @column = column
12
- @class_name = class_name
13
- end
14
-
15
- # Returns a symbol with the column type according to the database.
16
- def column_type
17
- class_name.columns_hash[@column.to_s].type
18
- end
19
-
20
- # Returns the value to this column in the row hash. The value is
21
- # finding by symbol or string key to be most flexible.
22
- def column_value
23
- row.fetch(column){row[@column.to_s]}
24
- end
25
-
26
- # Returns the default column value and it's added to the query if
27
- # the row hash does not contains column value.
28
- def default_value
29
- default_db_value ? default_db_value.to_s : "null"
30
- end
31
-
32
- # Returns the default database column value using methods that
33
- # ActiveRecord provides.
34
- def default_db_value
35
- class_name.columns_hash[@column.to_s].default
36
- end
37
-
38
- # Returns the valid column value to be included in the query.
39
- # The value depends of the database engine.
40
- def build
41
- column_value.nil? ? default_value : send(:"column_value_#{column_type}")
42
- end
43
-
44
- # Returns the correct value when column value is string, text,
45
- # date, time, datetime, timestamp.
46
- def column_value_string
47
- "'#{column_value}'"
48
- end
49
- alias :column_value_text :column_value_string
50
- alias :column_value_date :column_value_string
51
- alias :column_value_binary :column_value_string
52
-
53
- def column_value_time
54
- case Utilities.adapter
55
- when 'mysql2' then format = "%Y-%m-%d %H:%M:%S"
56
- when 'sqlserver' then format = "%Y-%m-%d %H:%M:%S.%3N"
57
- else format = "%Y-%m-%d %H:%M:%S.%6N"
58
- end
59
- "'#{column_value.strftime(format)}'"
60
- end
61
- alias :column_value_timestamp :column_value_time
62
- alias :column_value_datetime :column_value_time
63
-
64
- # Returns the correct value to integer column.
65
- def column_value_integer
66
- column_value.to_i.to_s
67
- end
68
-
69
- # Returns the correct value to decimal or float column.
70
- def column_value_decimal
71
- column_value.to_f.to_s
72
- end
73
- alias :column_value_float :column_value_decimal
74
-
75
- # Returns the correct value to boolean column. This column calls
76
- # the correct method according to the database adapter.
77
- def column_value_boolean
78
- case Utilities.adapter
79
- when 'mysql2', 'postgresql'
80
- column_value ? "true" : "false"
81
- when 'sqlite3', 'sqlserver'
82
- column_value ? "1" : "0"
83
- end
84
- end
85
-
86
- end
87
- end
88
- end
89
- end
90
- end
@@ -1,7 +0,0 @@
1
- module MassInsert
2
- module Builder
3
- module Adapters
4
- class Mysql2Adapter < Adapter; end
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module MassInsert
2
- module Builder
3
- module Adapters
4
- class PostgreSQLAdapter < Adapter; end
5
- end
6
- end
7
- end
@@ -1,27 +0,0 @@
1
- module MassInsert
2
- module Builder
3
- module Adapters
4
- class SQLite3Adapter < Adapter
5
-
6
- # Returns the amount of records to each query. Tries to take the
7
- # each_slice option value or 500 due it's a standard in SQLite.
8
- def values_per_insertion
9
- each_slice || 500
10
- end
11
-
12
- # The method is overwrited because the queries structure to Sqlite3
13
- # adapter are different.
14
- def string_values
15
- "SELECT #{string_rows_values};"
16
- end
17
-
18
- # The method is overwrited because the record separator to sqlite adapter
19
- # is different.
20
- def string_rows_values
21
- values.map{ |row| string_single_row_values(row) }.join(" UNION SELECT ")
22
- end
23
-
24
- end
25
- end
26
- end
27
- end