Empact-ar-extensions 0.9.2

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.
Files changed (45) hide show
  1. data/ChangeLog +145 -0
  2. data/README +167 -0
  3. data/Rakefile +61 -0
  4. data/config/database.yml +7 -0
  5. data/config/database.yml.template +7 -0
  6. data/config/mysql.schema +72 -0
  7. data/config/postgresql.schema +39 -0
  8. data/db/migrate/generic_schema.rb +97 -0
  9. data/db/migrate/mysql_schema.rb +32 -0
  10. data/db/migrate/oracle_schema.rb +5 -0
  11. data/db/migrate/version.rb +4 -0
  12. data/init.rb +31 -0
  13. data/lib/ar-extensions.rb +5 -0
  14. data/lib/ar-extensions/adapters/abstract_adapter.rb +146 -0
  15. data/lib/ar-extensions/adapters/mysql.rb +10 -0
  16. data/lib/ar-extensions/adapters/oracle.rb +14 -0
  17. data/lib/ar-extensions/adapters/postgresql.rb +9 -0
  18. data/lib/ar-extensions/adapters/sqlite.rb +7 -0
  19. data/lib/ar-extensions/create_and_update.rb +508 -0
  20. data/lib/ar-extensions/create_and_update/mysql.rb +7 -0
  21. data/lib/ar-extensions/csv.rb +309 -0
  22. data/lib/ar-extensions/delete.rb +143 -0
  23. data/lib/ar-extensions/delete/mysql.rb +3 -0
  24. data/lib/ar-extensions/extensions.rb +509 -0
  25. data/lib/ar-extensions/finder_options.rb +275 -0
  26. data/lib/ar-extensions/finder_options/mysql.rb +6 -0
  27. data/lib/ar-extensions/finders.rb +96 -0
  28. data/lib/ar-extensions/foreign_keys.rb +70 -0
  29. data/lib/ar-extensions/fulltext.rb +62 -0
  30. data/lib/ar-extensions/fulltext/mysql.rb +44 -0
  31. data/lib/ar-extensions/import.rb +354 -0
  32. data/lib/ar-extensions/import/mysql.rb +50 -0
  33. data/lib/ar-extensions/import/postgresql.rb +0 -0
  34. data/lib/ar-extensions/import/sqlite.rb +22 -0
  35. data/lib/ar-extensions/insert_select.rb +178 -0
  36. data/lib/ar-extensions/insert_select/mysql.rb +7 -0
  37. data/lib/ar-extensions/synchronize.rb +30 -0
  38. data/lib/ar-extensions/temporary_table.rb +131 -0
  39. data/lib/ar-extensions/temporary_table/mysql.rb +3 -0
  40. data/lib/ar-extensions/union.rb +204 -0
  41. data/lib/ar-extensions/union/mysql.rb +6 -0
  42. data/lib/ar-extensions/util/sql_generation.rb +27 -0
  43. data/lib/ar-extensions/util/support_methods.rb +32 -0
  44. data/lib/ar-extensions/version.rb +9 -0
  45. metadata +128 -0
data/ChangeLog ADDED
@@ -0,0 +1,145 @@
1
+ 2009-07-22 zdennis <zach.dennis@gmail.com>
2
+
3
+ * Forgot to push past commit of fixing #sanitize_sql method signatures to supported passing in a table_name. This satisfies the change to the ActiveRecord API in Rails commit 489abfd3b23f3c4b3de86aeb3bde3970771c001b on April 20th.
4
+
5
+ 2009-04-17 blythedunham <blythedunham@gmail.com>
6
+
7
+ * Added MySQL support for save, create, replace options - :ignore, :on_duplicate_key_update, :keywords, :reload, :keywords, :pre_sql, :post_sql
8
+ * Added MySQL support for find options: :keywords, :pre_sql, :post_sql, :index_hint
9
+ * Added MySQL support for find_union and count_union
10
+ * Added MySQL support for insert_select
11
+ * Added MySQL support for delete_duplicates and delete_all :batch_size => X
12
+ * Updated :on_duplicate_update_key to accept a string in addition to array
13
+ * Fixed Find Extension Range bug to exclude end when ... used instead of ..
14
+
15
+ 2009-03-16 zdennis <zach.dennis@gmail.com>
16
+
17
+ * fixed Rails 2.3.1 and 2.3.2 compatibility issue (Stephen Heuer)
18
+
19
+ 2009-02-09 zdennis <zach.dennis@gmail.com>
20
+
21
+ * fixed issue in http://zdennis.lighthouseapp.com/projects/14379/tickets/14-join-table-conditions-broken
22
+ * Updated usage of Inflector to point to ActiveSupport::Inflector
23
+ * Fixed bug where finder conditions which use arext-suffixed keys and normal field keys would fail when using a conditions hash. (Gabe da Silveira)
24
+ * added timestamps options to not automatically add timestamps even if record timestamps is disabled in ActiveRecord::Base (Thibaud Guillaume-Gentil)
25
+ * Updated to use alias_method_chain so that multiple aliased finders remain intact (Marcus Crafter)
26
+
27
+ 2007-07-20 zdennis <zdennis@dhcp-22.atomicobject.localnet>
28
+
29
+ * Added patch from Michael Flester to fix bug with created_at/updated_at fields to use proper timezone.
30
+
31
+ 2007-07-18 zdennis <zdennis@dhcp-22.atomicobject.localnet>
32
+
33
+ * Added patch for Oracle support from Michael Flester.
34
+
35
+ 2007-05-05 zdennis <zdennis@elijah.local>
36
+
37
+ * Added ActiveRecord::Base::AbstractAdapter#synchronize method which allows a mass re-synchronization of ActiveRecord instances. This is similar to ActiveRecord::Base#reload except that it works on multiple instances at a time rather then one. This sends one query for all instances rather then 1 per instance reloaded.
38
+
39
+ * Fixed bug with URI encoded strings with a workaround in the Comparison extension. ActiveRecord needs to be fixed to not use the String#% method so strings that do contains percentage signs will not fail
40
+
41
+ * Applied patch from Grant Goodale to allow the Like extension to support arrays when using the '_contains' suffix
42
+
43
+ 2007-03-14 zdennis <zdennis@elijah.xrite.com>
44
+
45
+ * Fixed a bug by renaming the alias for the ActiveRecord::Base#quote method in finders.rb. See rubyforge bug #8996
46
+
47
+ * Made a .gemspec for ar-extensions
48
+
49
+ 2007-03-13 zdennis <zdennis@elijah>
50
+
51
+ * Added :datetime searching support for better finder support.
52
+
53
+ 2007-02-11 zdennis <zdennis@admin.aries>
54
+
55
+ * Updated to_csv and import functionality to work with Sqlite, Sqlite3, PostgreSQL and MySQL
56
+
57
+ * Updated RDOC for import, to_csv, better finders, temporary tables and foreign key support
58
+
59
+ 2007-01-29 zdennis <zdennis@mktec.com>
60
+
61
+ * Added initial support for temporary tables and permanent like tables.
62
+
63
+ 2007-01-24 zdennis <zdennis@mktec.com>
64
+
65
+ * Added dependency for Mocha 0.4.0 or higher for testing
66
+
67
+ * Fixed bug for import functionality where it was never actually splitting up values correctly (thx to Mark Van Holstyn!!)
68
+
69
+ 2007-01-09 zdennis <zdennis@aries>
70
+
71
+ * Added support for embedded to_csv includes
72
+
73
+ 2007-01-07 zdennis <zdennis@aries>
74
+
75
+ * Added fix to init.rb to only load CSV functionality if FasterCSV
76
+ is available, otherwise print a message to STDERR and continue.
77
+
78
+ * Added fix to tests/boot.rb which solves fixture_path issues in
79
+ ActiveRecord 1.14.4 and earlier. The fix is included Rails trunk
80
+ and will be available in Rails 1.2.
81
+
82
+ 2007-01-05 zdennis <zdennis@aries>
83
+
84
+ * Added ActiveRecord::Extensions::VERSION module which has the following constants: MAJOR, MINOR, REVISION
85
+
86
+ * Running rake tests are now smart enough to rebuild the database if they are required based on schema_info table.
87
+
88
+ * Added schema_info table for test database schemas.
89
+
90
+ 2006-12-29 zdennis <zdennis@aries>
91
+
92
+ * Updated the Rakefile to run an external ruby process when running test files rather then in the same ruby process that runs the Rakefile
93
+
94
+ * Updated the directory structure of lib/ to solve namespace issues.
95
+
96
+ 2006-12-22 Zach Dennis <zdennis@silver.dennis.network>
97
+
98
+ * Added rake tasks for sqlite and sqlite3 databases
99
+
100
+ * Added "does_not_match" as a suffix to better finders when working with Regular Expressions
101
+
102
+ * Added "not_between" suffix to better finders when working with Ranges
103
+
104
+ 2006-12-17 zdennis <zdennis@aries>
105
+
106
+ * Added :only and :except options to to_csv method. Forcing
107
+ compatibility with http://blog.integralimpressions.com/articles/2006/09/01/tocsv-plugin
108
+
109
+ * Changed to_csv option :headers take a boolean rather then an
110
+ array of column names.
111
+
112
+ * Added rake task db:prepare_<adapter_name> to build test
113
+ database.
114
+
115
+ 2006-12-16 Zach Dennis <zdennis@silver.dennis.network>
116
+
117
+ * Added more tests for better finder support
118
+
119
+ * Added to_csv support for Arrays returned by ActiveRecord::Base.find
120
+
121
+ * Refactored ActiveRecord::Extensions::Registry to use an Array instead of hash
122
+
123
+ 2006-12-06 Zach Dennis <zdennis@silver.dennis.network>
124
+
125
+ * PostgreSQL has tested support for everything MySQL has except for Full Text Searching. This is not implemented.
126
+
127
+ * Refactored how import and full text searching implementation is handled, this is largely handled by duck typing certain method calls.
128
+
129
+ * Added generic import support for any adapter that doesn't support multi-value insert statements. This provides generic support which is guaranteed to be no slower then ActiveRecord#create.
130
+
131
+ 2006-11-23 Zach Dennis <zdennis@silver.dennis.network>
132
+
133
+ * Added finder support for PostgreSQL including Regexp Searching. (No full text searching though)
134
+
135
+ * Fixed bug in finders.rb where NULL searches were not correctly being translated into IS NULL when doing { :column => nil }
136
+
137
+ 2006-11-20 Zach Dennis <zach.dennis@gmail.com>
138
+
139
+ * Refactored core finder components out into ActiveRecord extensions
140
+
141
+ * Duck typing support for any object that is passed in to a conditions hash. ie: MyModel.find( :all, :conditions=>{ :name=>NameSearchObject.new } )
142
+
143
+ * Duck typing support for any object that is passed in as a condition. ie: MyModel.find( :all, :conditions=>SearchObject.new )
144
+
145
+
data/README ADDED
@@ -0,0 +1,167 @@
1
+ LICENSE
2
+ ----------
3
+ This is licensed under the ruby license.
4
+
5
+ Author: Zach Dennis
6
+ Web Site: http://www.continuousthinking.com/tags/arext
7
+ Email: zach.dennis@gmail.com
8
+
9
+ - For How-To information see http://www.continuousthinking.com/tags/arext
10
+ - For project information and feedback please consult http://rubyforge.org/projects/arext/
11
+ - For release information please see below
12
+
13
+ ActiveRecord::Extensions 0.9.0, 0.9.1
14
+ ------------------------------
15
+ April 17, 2009
16
+ - Added MySQL support for save, create, replace options - :ignore, :on_duplicate_key_update, :keywords, :reload, :keywords, :pre_sql, :post_sql
17
+ - Added MySQL support for find options: :keywords, :pre_sql, :post_sql, :index_hint
18
+ - Added MySQL support for find_union and count_union
19
+ - Added MySQL support for insert_select
20
+ - Added MySQL support for delete_duplicates and delete_all :batch_size => X
21
+ - Updated :on_duplicate_update_key to accept a string in addition to array
22
+ - Fixed Find Extension Range bug to exclude end when ... used instead of ..
23
+
24
+ ActiveRecord::Extensions 0.8.2
25
+ ------------------------------
26
+ March 16th, 2009
27
+ - Rails 2.3.1 and 2.3.2 compatibility added
28
+ - Rails 2.1.2 and 2.2.2 compatibility preserved
29
+
30
+ AciveRecord::Extensions 0.7.0
31
+ -----------------------------
32
+ July 20th, 2007
33
+ - Fixes timezone issue (thanks Michael Flester)
34
+ - Adds better finder and import support for Oracle (thanks Michael Flester)
35
+ - Committed patch to fix MySQL query padding, thanks to Gabe da Silveira
36
+ - Added functionality for MySQL to work with created_on, created_at, updated_on or updated_at fields
37
+ - Added more test coverage for import functionality
38
+
39
+ ActiveRecord::Extensions 0.6.0
40
+ ------------------------------
41
+ May 5th, 2007
42
+ - Fixed bug with URI escaped strings and the Comparison better finder extension
43
+ - Added support for arrays with the Like better finder extension when using the '_contains' suffix
44
+ - Added 'synchronize' support for ActiveRecord::Base instances when using Import functionality
45
+
46
+ ActiveRecord::Extensions 0.5.2
47
+ ------------------------------
48
+ March 14th, 2007
49
+ - Fixed Rubyforge bug #8996 by renaming alias in finders.rb to the ActiveRecord::Base#quote method
50
+
51
+ ActiveRecord::Extensions 0.5.1
52
+ ------------------------------
53
+ March 14th, 2007
54
+ - Released as a rubygem
55
+ - Added a .gemspec file
56
+
57
+ ActiveRecord::Extensions 0.5.0
58
+ ------------------------------
59
+ March 13th, 2007
60
+ - Added Time based query support which works on ActiveRecord columns which match a type supported by :datetime
61
+
62
+ ActiveRecord::Extensions 0.4.0
63
+ ------------------------------
64
+ February 11th, 2007
65
+ - Added to_csv functionality
66
+ - Added temporary table support (MySQL)
67
+ - Added foreign key support (MySQL)
68
+ - Updated tests to keep schema information. Test database will automatically rebuild themselves if they are out of sync
69
+ - Added dependency for Mocha 0.4.0 or higher for tests
70
+
71
+ ActiveRecord::Extensions 0.3.0
72
+ ------------------------------
73
+ December 29th, 2006
74
+ - Updates to the lib/ directory structure to avoid namespace issues.
75
+ - Updates to the Rakefile to run an external ruby process for tests rather then the same
76
+ ruby process that runs the rake tasks
77
+
78
+ ActiveRecord::Extensions 0.2.0
79
+ ------------------------------
80
+ December 22nd, 2006
81
+ - Updates to_csv method for arrays returned by ActiveRecord::Base.find
82
+ - Adds does_not_match suffix for regular expression based conditions, ie: :field_does_not_match => /regex/
83
+ - Adds not_between suffix for ange based conditions, ie: :id_not_between => ( 0 .. 1 )
84
+ - Adds SQLite and SQLite3 support for better finders.
85
+ - Updates rake tasks for sqlite and sqlite3.
86
+ - Added rake tasks to use database migrations rather then raw SQL schema files.
87
+
88
+ ActiveRecord::Extensions 0.1.0
89
+ -------------------------------
90
+ December 16th, 2006
91
+ - Adds to_csv method to arrays returned by ActiveRecord::Base.find.
92
+ - Fixes bug in ActiveRecord::Extensions::Registry when processing key/value pairs where
93
+ the order of certain Extensions was not handled correctly due to Hash usage.
94
+ - Refactoring of ActiveRecord::Extensions::Registry
95
+ - Added more tests for better finder support
96
+
97
+ ActiveRecord::Extensions 0.0.6
98
+ ------------------------------
99
+ December 5th, 2006
100
+ - Added generic support for import functionality for all adapters
101
+ - Includes rake testing tasks for postgresql
102
+ - Includes postgresql support for all extensions except for full text searching (which is only mysql)
103
+ - Refactored directory structure of tests, import functionality and fulltext functionality
104
+
105
+
106
+ ActiveRecord::Extensions 0.0.5
107
+ ------------------------------
108
+ October 20th, 2006.
109
+ - Fixes two bugs which broke normal ActiveRecord behavior
110
+ - Fully complaint with Rails 1.1.0 thru 1.1.6 (and all ActiveRecord versions released with those)
111
+ - Inlcudes new Rakefile
112
+ - Includes rake task "test:mysql" which allows ActiveRecord::Extensions to be tested with mysql
113
+ - Includes rake test "test:activerecord:mysql" which allows ActiveRecord's tests to be tested with the
114
+ ActiveRecord::Extensions library
115
+
116
+
117
+ ActiveRecord::Extensions 0.0.4
118
+ -------------------------------
119
+ August 26th, 2006. Released at RubyConf*MI.
120
+ September 24th, 2006, Rubyforge release.
121
+ - Inlcudes "Better Finder" support for ActiveRecord
122
+ http://blogs.mktec.com/zdennis/pages/ARE_finders
123
+
124
+
125
+ ActiveRecord::Extensions 0.0.3
126
+ -------------------------------
127
+ Released.... ????
128
+ - the project has been named ActiveRecord::Extensions.
129
+
130
+
131
+ ActiveRecord::Optimizations 0.0.2
132
+ ---------------------------------
133
+ July 20th, 11:27pm, Zach Dennis
134
+
135
+ This includes some of the optimizations for the ActiveRecord::Base. This release only supports the MysqlAdapter, although other adapters will be supported in upcoming releases.
136
+
137
+ HOW-TO USAGE
138
+ ------------
139
+ Require the two files in the lib/ directory and then create records using:
140
+ Model.create array_of_hashes
141
+
142
+ Example:
143
+ class LogEntry < ActiveRecord::Base ; end
144
+ LogEntry.import [ { :log_entry_name=>"Name" }, {:log_entry_name=>"Name2"}, ... ], :optimize=>true
145
+
146
+ Using the optimized create method will return the number of inserts performed, rather then an array of LogEntry objects. This currently skips model validation.
147
+
148
+
149
+ CHANGELOG
150
+ ----------
151
+ 0.0.2
152
+ - add some documentation to the updated methods for ActiveRecord and MysqlAdapter
153
+ - renamed the create optimizatin to import. Multi-value inserts can be obtained using ActiveRecord::Base.import
154
+ 0.0.1
155
+ - introduced updates to ActiveRecord::Base.create to support multi-value inserts
156
+
157
+
158
+ UPCOMING
159
+ ----------
160
+ - model validation on imports
161
+ - postgresql support for imports
162
+ - ability to use regular expressions for db searches
163
+ - ability to use db functions
164
+ - temporary table support
165
+ - memory table support
166
+ - complex update with on duplicate key update support
167
+
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ require "pathname"
2
+ require "rubygems"
3
+ require "rake"
4
+ require "rake/testtask"
5
+
6
+ DIR = Pathname.new(File.dirname(__FILE__))
7
+ ADAPTERS = %w(mysql postgresql sqlite sqlite3 oracle)
8
+
9
+ task :default => ["test:mysql"]
10
+
11
+ task :boot do
12
+ require DIR.join("lib", "ar-extensions").expand_path
13
+ require DIR.join("db", "migrate", "version").expand_path
14
+ end
15
+
16
+ ADAPTERS.each do |adapter|
17
+ namespace :db do
18
+ namespace :test do
19
+ desc "Builds test database for #{adapter}"
20
+ task "prepare_#{adapter}" do
21
+ ruby "#{DIR.join('tests', 'prepare.rb')} #{adapter}"
22
+ end
23
+ end
24
+ end
25
+
26
+ namespace :test do
27
+ desc "Test base extensions for #{adapter}"
28
+ task(adapter) do
29
+ ENV["ARE_DB"] = adapter
30
+ Rake::Task["db:test:prepare_#{adapter}"].invoke
31
+ ruby "#{DIR.join('tests', 'run.rb')} #{adapter}"
32
+ end
33
+ end
34
+
35
+ namespace :activerecord do
36
+ desc "Runs ActiveRecord unit tests for #{adapter} with ActiveRecord::Extensions"
37
+ task(adapter) do
38
+ activerecord_dir = ARGV[1]
39
+ if activerecord_dir.nil? || !File.directory?(activerecord_dir)
40
+ puts "ERROR: Pass in the path to ActiveRecord. Eg: /home/zdennis/rails_trunk/activerecord"
41
+ exit
42
+ end
43
+
44
+ old_dir, old_env = Dir.pwd, ENV["RUBYOPT"]
45
+ Dir.chdir(activerecord_dir)
46
+ ENV["RUBYOPT"] = "-r#{File.join(old_dir,'init.rb')}"
47
+
48
+ load "Rakefile"
49
+
50
+ Rake::Task["test_#{adapter}"].invoke
51
+ Dir.chdir(old_dir)
52
+ ENV["RUBYOPT"] = old_env
53
+ end
54
+
55
+ desc "Runs ActiveRecord unit tests for #{adapter} with ActiveRecord::Extensions with ALL available #{adapter} functionality"
56
+ task "#{adapter}_all" do
57
+ ENV["LOAD_ADAPTER_EXTENSIONS"] = adapter
58
+ Rake::Task["test:activerecord:#{adapter}"].invoke
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,7 @@
1
+ development:
2
+ adapter: mysql
3
+ database: aroptests
4
+ username: rails
5
+ password:
6
+ port: 3306
7
+ host: localhost
@@ -0,0 +1,7 @@
1
+ development:
2
+ adapter: mysql
3
+ database: aroptests
4
+ username: rails
5
+ password:
6
+ port: 3306
7
+ host: localhost
@@ -0,0 +1,72 @@
1
+
2
+ create table test_myisam(
3
+ id int(11) unsigned not null auto_increment,
4
+ my_name varchar(20) not null,
5
+ description varchar(255) default '',
6
+ primary key (id)
7
+ )ENGINE=MyISAM;
8
+
9
+
10
+ create table test_innodb(
11
+ id int(11) unsigned not null auto_increment,
12
+ my_name varchar(20) not null,
13
+ description varchar(255) default '',
14
+ primary key (id)
15
+ )ENGINE=InnoDb;
16
+
17
+
18
+ create table test_memory(
19
+ id int(11) unsigned not null auto_increment,
20
+ my_name varchar(20) not null,
21
+ description varchar(255) default '',
22
+ primary key (id)
23
+ )ENGINE=memory;
24
+
25
+
26
+ create temporary table test_temp(
27
+ id int(11) unsigned not null auto_increment,
28
+ my_name varchar(20) not null,
29
+ description varchar(255) default '',
30
+ primary key (id)
31
+ );
32
+
33
+ CREATE TABLE `topics` (
34
+ `id` int(11) NOT NULL auto_increment,
35
+ `title` varchar(255) default NULL,
36
+ `author_name` varchar(255) default NULL,
37
+ `author_email_address` varchar(255) default NULL,
38
+ `written_on` datetime default NULL,
39
+ `bonus_time` time default NULL,
40
+ `last_read` date default NULL,
41
+ `content` text,
42
+ `approved` tinyint(1) default '1',
43
+ `replies_count` int(11) default '0',
44
+ `parent_id` int(11) default NULL,
45
+ `type` varchar(50) default NULL,
46
+ PRIMARY KEY (`id`)
47
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
48
+
49
+ CREATE TABLE `projects` (
50
+ `id` int(11) NOT NULL auto_increment,
51
+ `name` varchar(100) default NULL,
52
+ `type` varchar(255) NOT NULL,
53
+ PRIMARY KEY (`id`)
54
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
55
+
56
+ CREATE TABLE `developers` (
57
+ `id` int(11) NOT NULL auto_increment,
58
+ `name` varchar(100) default NULL,
59
+ `salary` int(11) default '70000',
60
+ `created_at` datetime default NULL,
61
+ `updated_at` datetime default NULL,
62
+ PRIMARY KEY (`id`)
63
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
64
+
65
+ CREATE TABLE `books` (
66
+ `id` int(11) NOT NULL auto_increment,
67
+ `title` varchar(255) NOT NULL,
68
+ `publisher` varchar(255) NOT NULL,
69
+ `author_name` varchar(255) NOT NULL,
70
+ PRIMARY KEY (`id`),
71
+ FULLTEXT( `title`, `publisher`, `author_name` )
72
+ ) ENGINE=MyISAM;