activerecord_execute_raw 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +22 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/activerecord_execute_raw.rb +24 -0
- data/spec/activerecord_execute_raw_spec.rb +4 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +87 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Trampoline Systems Ltd
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= activerecord_execute_raw
|
2
|
+
|
3
|
+
ActiveRecord-JDBC's implementation of connection.execute() test the executed sql, and
|
4
|
+
if it's an insert statement it fetches inserted ids after the statement is executed.
|
5
|
+
this is a problem if you are inserting millions of rows
|
6
|
+
|
7
|
+
activerecord_execute_raw creates a connection.execute_raw() method which bypasses the
|
8
|
+
id fetch
|
9
|
+
|
10
|
+
== Note on Patches/Pull Requests
|
11
|
+
|
12
|
+
* Fork the project.
|
13
|
+
* Make your feature addition or bug fix.
|
14
|
+
* Add tests for it. This is important so I don't break it in a
|
15
|
+
future version unintentionally.
|
16
|
+
* Commit, do not mess with rakefile, version, or history.
|
17
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
18
|
+
* Send me a pull request. Bonus points for topic branches.
|
19
|
+
|
20
|
+
== Copyright
|
21
|
+
|
22
|
+
Copyright (c) 2010 Trampoline Systems Ltd. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "activerecord_execute_raw"
|
8
|
+
gem.summary = %Q{execute raw sql on db from ActiveRecord [without fetching inserted ids as done by ActiveRecord-JDBC]}
|
9
|
+
gem.description = %Q{ActiveRecord-JDBC fetches ids of inserted records when you call connection.execute(). this
|
10
|
+
gem adds a connection.execute_raw() method which does not fetch inserted ids}
|
11
|
+
gem.email = "mccraigmccraig@googlemail.com"
|
12
|
+
gem.homepage = "http://github.com/trampoline/activerecord_execute_raw"
|
13
|
+
gem.authors = ["mccraig mccraig of the clan mccraig"]
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
gem.add_development_dependency "yard", ">= 0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :spec => :check_dependencies
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
begin
|
40
|
+
require 'yard'
|
41
|
+
YARD::Rake::YardocTask.new
|
42
|
+
rescue LoadError
|
43
|
+
task :yardoc do
|
44
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
45
|
+
end
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# ActiveRecord::ConnectionAdapters::JdbcAdapter always fetches inserted ids
|
2
|
+
# after executing an insert statement through connection.execute() . this
|
3
|
+
# is a problem when millions of rows are inserted
|
4
|
+
|
5
|
+
# define a base method so we don't need to care about whether
|
6
|
+
# we are actually using jdbc or not
|
7
|
+
class ActiveRecord::ConnectionAdapters::AbstractAdapter
|
8
|
+
def execute_raw(sql, name = nil)
|
9
|
+
execute(sql, name)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# then override the base method on the JdbcAdapter
|
14
|
+
class ActiveRecord::ConnectionAdapters::JdbcAdapter
|
15
|
+
def execute_raw(sql, name = nil)
|
16
|
+
log(sql, name) do
|
17
|
+
if ActiveRecord::ConnectionAdapters::JdbcConnection::select?(sql)
|
18
|
+
@connection.execute_query(sql)
|
19
|
+
else
|
20
|
+
@connection.execute_update(sql)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord_execute_raw
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mccraig mccraig of the clan mccraig
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-19 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: |-
|
36
|
+
ActiveRecord-JDBC fetches ids of inserted records when you call connection.execute(). this
|
37
|
+
gem adds a connection.execute_raw() method which does not fetch inserted ids
|
38
|
+
email: mccraigmccraig@googlemail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- LICENSE
|
50
|
+
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- lib/activerecord_execute_raw.rb
|
54
|
+
- spec/activerecord_execute_raw_spec.rb
|
55
|
+
- spec/spec.opts
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/trampoline/activerecord_execute_raw
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --charset=UTF-8
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.5
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: execute raw sql on db from ActiveRecord [without fetching inserted ids as done by ActiveRecord-JDBC]
|
85
|
+
test_files:
|
86
|
+
- spec/activerecord_execute_raw_spec.rb
|
87
|
+
- spec/spec_helper.rb
|