ar-extensions 0.5.1
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.
- data/ChangeLog +97 -0
- data/README +123 -0
- data/Rakefile +97 -0
- data/config/database.yml +7 -0
- data/config/database.yml.template +7 -0
- data/config/mysql.schema +72 -0
- data/config/postgresql.schema +39 -0
- data/db/migrate/generic_schema.rb +59 -0
- data/db/migrate/mysql_schema.rb +26 -0
- data/db/migrate/version.rb +4 -0
- data/init.rb +32 -0
- data/lib/ar-extensions.rb +4 -0
- data/lib/ar-extensions/adapters/abstract_adapter.rb +83 -0
- data/lib/ar-extensions/adapters/mysql_adapter.rb +14 -0
- data/lib/ar-extensions/adapters/postgresql.rb +7 -0
- data/lib/ar-extensions/csv.rb +302 -0
- data/lib/ar-extensions/extensions.rb +474 -0
- data/lib/ar-extensions/finders.rb +76 -0
- data/lib/ar-extensions/foreign_keys.rb +70 -0
- data/lib/ar-extensions/fulltext.rb +63 -0
- data/lib/ar-extensions/fulltext/mysql.rb +44 -0
- data/lib/ar-extensions/import.rb +254 -0
- data/lib/ar-extensions/import/mysql.rb +70 -0
- data/lib/ar-extensions/import/postgresql.rb +0 -0
- data/lib/ar-extensions/temporary_table.rb +124 -0
- data/lib/ar-extensions/temporary_table/mysql.rb +3 -0
- data/lib/ar-extensions/version.rb +8 -0
- metadata +83 -0
data/ChangeLog
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
2007-03-13 zdennis <zdennis@elijah>
|
2
|
+
|
3
|
+
* Added :datetime searching support for better finder support.
|
4
|
+
|
5
|
+
2007-02-11 zdennis <zdennis@admin.aries>
|
6
|
+
|
7
|
+
* Updated to_csv and import functionality to work with Sqlite, Sqlite3, PostgreSQL and MySQL
|
8
|
+
|
9
|
+
* Updated RDOC for import, to_csv, better finders, temporary tables and foreign key support
|
10
|
+
|
11
|
+
2007-01-29 zdennis <zdennis@mktec.com>
|
12
|
+
|
13
|
+
* Added initial support for temporary tables and permanent like tables.
|
14
|
+
|
15
|
+
2007-01-24 zdennis <zdennis@mktec.com>
|
16
|
+
|
17
|
+
* Added dependency for Mocha 0.4.0 or higher for testing
|
18
|
+
|
19
|
+
* Fixed bug for import functionality where it was never actually splitting up values correctly (thx to Mark Van Holstyn!!)
|
20
|
+
|
21
|
+
2007-01-09 zdennis <zdennis@aries>
|
22
|
+
|
23
|
+
* Added support for embedded to_csv includes
|
24
|
+
|
25
|
+
2007-01-07 zdennis <zdennis@aries>
|
26
|
+
|
27
|
+
* Added fix to init.rb to only load CSV functionality if FasterCSV
|
28
|
+
is available, otherwise print a message to STDERR and continue.
|
29
|
+
|
30
|
+
* Added fix to tests/boot.rb which solves fixture_path issues in
|
31
|
+
ActiveRecord 1.14.4 and earlier. The fix is included Rails trunk
|
32
|
+
and will be available in Rails 1.2.
|
33
|
+
|
34
|
+
2007-01-05 zdennis <zdennis@aries>
|
35
|
+
|
36
|
+
* Added ActiveRecord::Extensions::VERSION module which has the following constants: MAJOR, MINOR, REVISION
|
37
|
+
|
38
|
+
* Running rake tests are now smart enough to rebuild the database if they are required based on schema_info table.
|
39
|
+
|
40
|
+
* Added schema_info table for test database schemas.
|
41
|
+
|
42
|
+
2006-12-29 zdennis <zdennis@aries>
|
43
|
+
|
44
|
+
* Updated the Rakefile to run an external ruby process when running test files rather then in the same ruby process that runs the Rakefile
|
45
|
+
|
46
|
+
* Updated the directory structure of lib/ to solve namespace issues.
|
47
|
+
|
48
|
+
2006-12-22 Zach Dennis <zdennis@silver.dennis.network>
|
49
|
+
|
50
|
+
* Added rake tasks for sqlite and sqlite3 databases
|
51
|
+
|
52
|
+
* Added "does_not_match" as a suffix to better finders when working with Regular Expressions
|
53
|
+
|
54
|
+
* Added "not_between" suffix to better finders when working with Ranges
|
55
|
+
|
56
|
+
2006-12-17 zdennis <zdennis@aries>
|
57
|
+
|
58
|
+
* Added :only and :except options to to_csv method. Forcing
|
59
|
+
compatibility with http://blog.integralimpressions.com/articles/2006/09/01/tocsv-plugin
|
60
|
+
|
61
|
+
* Changed to_csv option :headers take a boolean rather then an
|
62
|
+
array of column names.
|
63
|
+
|
64
|
+
* Added rake task db:prepare_<adapter_name> to build test
|
65
|
+
database.
|
66
|
+
|
67
|
+
2006-12-16 Zach Dennis <zdennis@silver.dennis.network>
|
68
|
+
|
69
|
+
* Added more tests for better finder support
|
70
|
+
|
71
|
+
* Added to_csv support for Arrays returned by ActiveRecord::Base.find
|
72
|
+
|
73
|
+
* Refactored ActiveRecord::Extensions::Registry to use an Array instead of hash
|
74
|
+
|
75
|
+
2006-12-06 Zach Dennis <zdennis@silver.dennis.network>
|
76
|
+
|
77
|
+
* PostgreSQL has tested support for everything MySQL has except for Full Text Searching. This is not implemented.
|
78
|
+
|
79
|
+
* Refactored how import and full text searching implementation is handled, this is largely handled by duck typing certain method calls.
|
80
|
+
|
81
|
+
* 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.
|
82
|
+
|
83
|
+
2006-11-23 Zach Dennis <zdennis@silver.dennis.network>
|
84
|
+
|
85
|
+
* Added finder support for PostgreSQL including Regexp Searching. (No full text searching though)
|
86
|
+
|
87
|
+
* Fixed bug in finders.rb where NULL searches were not correctly being translated into IS NULL when doing { :column => nil }
|
88
|
+
|
89
|
+
2006-11-20 Zach Dennis <zach.dennis@gmail.com>
|
90
|
+
|
91
|
+
* Refactored core finder components out into ActiveRecord extensions
|
92
|
+
|
93
|
+
* Duck typing support for any object that is passed in to a conditions hash. ie: MyModel.find( :all, :conditions=>{ :name=>NameSearchObject.new } )
|
94
|
+
|
95
|
+
* Duck typing support for any object that is passed in as a condition. ie: MyModel.find( :all, :conditions=>SearchObject.new )
|
96
|
+
|
97
|
+
|
data/README
ADDED
@@ -0,0 +1,123 @@
|
|
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.5.0
|
14
|
+
------------------------------
|
15
|
+
March 13th, 2007
|
16
|
+
- Added Time based query support which works on ActiveRecord columns which match a type supported by :datetime
|
17
|
+
|
18
|
+
ActiveRecord::Extensions 0.4.0
|
19
|
+
------------------------------
|
20
|
+
February 11th, 2007
|
21
|
+
- Added to_csv functionality
|
22
|
+
- Added temporary table support (MySQL)
|
23
|
+
- Added foreign key support (MySQL)
|
24
|
+
- Updated tests to keep schema information. Test database will automatically rebuild themselves if they are out of sync
|
25
|
+
- Added dependency for Mocha 0.4.0 or higher for tests
|
26
|
+
|
27
|
+
ActiveRecord::Extensions 0.3.0
|
28
|
+
------------------------------
|
29
|
+
December 29th, 2006
|
30
|
+
- Updates to the lib/ directory structure to avoid namespace issues.
|
31
|
+
- Updates to the Rakefile to run an external ruby process for tests rather then the same
|
32
|
+
ruby process that runs the rake tasks
|
33
|
+
|
34
|
+
ActiveRecord::Extensions 0.2.0
|
35
|
+
------------------------------
|
36
|
+
December 22nd, 2006
|
37
|
+
- Updates to_csv method for arrays returned by ActiveRecord::Base.find
|
38
|
+
- Adds does_not_match suffix for regular expression based conditions, ie: :field_does_not_match => /regex/
|
39
|
+
- Adds not_between suffix for ange based conditions, ie: :id_not_between => ( 0 .. 1 )
|
40
|
+
- Adds SQLite and SQLite3 support for better finders.
|
41
|
+
- Updates rake tasks for sqlite and sqlite3.
|
42
|
+
- Added rake tasks to use database migrations rather then raw SQL schema files.
|
43
|
+
|
44
|
+
ActiveRecord::Extensions 0.1.0
|
45
|
+
-------------------------------
|
46
|
+
December 16th, 2006
|
47
|
+
- Adds to_csv method to arrays returned by ActiveRecord::Base.find.
|
48
|
+
- Fixes bug in ActiveRecord::Extensions::Registry when processing key/value pairs where
|
49
|
+
the order of certain Extensions was not handled correctly due to Hash usage.
|
50
|
+
- Refactoring of ActiveRecord::Extensions::Registry
|
51
|
+
- Added more tests for better finder support
|
52
|
+
|
53
|
+
ActiveRecord::Extensions 0.0.6
|
54
|
+
------------------------------
|
55
|
+
December 5th, 2006
|
56
|
+
- Added generic support for import functionality for all adapters
|
57
|
+
- Includes rake testing tasks for postgresql
|
58
|
+
- Includes postgresql support for all extensions except for full text searching (which is only mysql)
|
59
|
+
- Refactored directory structure of tests, import functionality and fulltext functionality
|
60
|
+
|
61
|
+
|
62
|
+
ActiveRecord::Extensions 0.0.5
|
63
|
+
------------------------------
|
64
|
+
October 20th, 2006.
|
65
|
+
- Fixes two bugs which broke normal ActiveRecord behavior
|
66
|
+
- Fully complaint with Rails 1.1.0 thru 1.1.6 (and all ActiveRecord versions released with those)
|
67
|
+
- Inlcudes new Rakefile
|
68
|
+
- Includes rake task "test:mysql" which allows ActiveRecord::Extensions to be tested with mysql
|
69
|
+
- Includes rake test "test:activerecord:mysql" which allows ActiveRecord's tests to be tested with the
|
70
|
+
ActiveRecord::Extensions library
|
71
|
+
|
72
|
+
|
73
|
+
ActiveRecord::Extensions 0.0.4
|
74
|
+
-------------------------------
|
75
|
+
August 26th, 2006. Released at RubyConf*MI.
|
76
|
+
September 24th, 2006, Rubyforge release.
|
77
|
+
- Inlcudes "Better Finder" support for ActiveRecord
|
78
|
+
http://blogs.mktec.com/zdennis/pages/ARE_finders
|
79
|
+
|
80
|
+
|
81
|
+
ActiveRecord::Extensions 0.0.3
|
82
|
+
-------------------------------
|
83
|
+
Released.... ????
|
84
|
+
- the project has been named ActiveRecord::Extensions.
|
85
|
+
|
86
|
+
|
87
|
+
ActiveRecord::Optimizations 0.0.2
|
88
|
+
---------------------------------
|
89
|
+
July 20th, 11:27pm, Zach Dennis
|
90
|
+
|
91
|
+
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.
|
92
|
+
|
93
|
+
HOW-TO USAGE
|
94
|
+
------------
|
95
|
+
Require the two files in the lib/ directory and then create records using:
|
96
|
+
Model.create array_of_hashes
|
97
|
+
|
98
|
+
Example:
|
99
|
+
class LogEntry < ActiveRecord::Base ; end
|
100
|
+
LogEntry.import [ { :log_entry_name=>"Name" }, {:log_entry_name=>"Name2"}, ... ], :optimize=>true
|
101
|
+
|
102
|
+
Using the optimized create method will return the number of inserts performed, rather then an array of LogEntry objects. This currently skips model validation.
|
103
|
+
|
104
|
+
|
105
|
+
CHANGELOG
|
106
|
+
----------
|
107
|
+
0.0.2
|
108
|
+
- add some documentation to the updated methods for ActiveRecord and MysqlAdapter
|
109
|
+
- renamed the create optimizatin to import. Multi-value inserts can be obtained using ActiveRecord::Base.import
|
110
|
+
0.0.1
|
111
|
+
- introduced updates to ActiveRecord::Base.create to support multi-value inserts
|
112
|
+
|
113
|
+
|
114
|
+
UPCOMING
|
115
|
+
----------
|
116
|
+
- model validation on imports
|
117
|
+
- postgresql support for imports
|
118
|
+
- ability to use regular expressions for db searches
|
119
|
+
- ability to use db functions
|
120
|
+
- temporary table support
|
121
|
+
- memory table support
|
122
|
+
- complex update with on duplicate key update support
|
123
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
DIR = File.dirname( __FILE__ )
|
6
|
+
|
7
|
+
task :default => [ "test:mysql" ]
|
8
|
+
|
9
|
+
task :boot do
|
10
|
+
require File.join( DIR, 'lib', 'ar-extensions' )
|
11
|
+
require File.join( DIR, 'tests', 'connections', "native_#{ENV['ARE_DB']}", 'connection' )
|
12
|
+
require File.join( DIR, 'db/migrate/version' )
|
13
|
+
end
|
14
|
+
|
15
|
+
ADAPTERS = %w( mysql postgresql sqlite sqlite3 )
|
16
|
+
|
17
|
+
namespace :db do
|
18
|
+
|
19
|
+
namespace :test do
|
20
|
+
ADAPTERS.each do |adapter|
|
21
|
+
desc "builds test database for #{adapter}"
|
22
|
+
task "prepare_#{adapter}" do |t|
|
23
|
+
file2run = File.join( DIR, 'tests/prepare.rb' )
|
24
|
+
system( "ruby #{file2run} #{adapter}" )
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
namespace :test do
|
32
|
+
|
33
|
+
ADAPTERS.each do |adapter|
|
34
|
+
desc "test base extensions for #{adapter}"
|
35
|
+
task adapter do |t|
|
36
|
+
ENV['ARE_DB'] = adapter
|
37
|
+
Rake::Task[ 'boot' ].invoke
|
38
|
+
|
39
|
+
task = Rake::Task[ "db:test:prepare_#{adapter}" ]
|
40
|
+
begin
|
41
|
+
task = false if SchemaInfo::VERSION == SchemaInfo.find( :first ).version
|
42
|
+
rescue Exception => ex
|
43
|
+
end
|
44
|
+
task.invoke if task
|
45
|
+
|
46
|
+
system "ruby #{File.join( DIR, 'tests/run.rb ' )} #{adapter}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
namespace :activerecord do
|
51
|
+
|
52
|
+
ADAPTERS.each do |adapter|
|
53
|
+
desc "runs ActiveRecord unit tests for #{adapter} with ActiveRecord::Extensions"
|
54
|
+
task adapter.to_sym do |t|
|
55
|
+
activerecord_dir = ARGV[1]
|
56
|
+
if activerecord_dir.nil? or ! File.directory?( activerecord_dir )
|
57
|
+
STDERR.puts "ERROR: Pass in the path to ActiveRecord. Eg: /home/zdennis/rails_trunk/activerecord"
|
58
|
+
exit
|
59
|
+
end
|
60
|
+
|
61
|
+
old_dir, old_env = Dir.pwd, ENV['RUBYOPT']
|
62
|
+
Dir.chdir( activerecord_dir )
|
63
|
+
ENV['RUBYOPT'] = "-r#{File.join(old_dir,'init.rb')}"
|
64
|
+
|
65
|
+
load "Rakefile"
|
66
|
+
Rake::Task[ "test_#{adapter}" ].invoke
|
67
|
+
Dir.chdir( old_dir )
|
68
|
+
ENV['RUBYOPT'] = old_env
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
namespace :gem do
|
76
|
+
|
77
|
+
ADAPTERS.each do |adapter|
|
78
|
+
desc "load ar-extensions from rubygems and test base extensions for #{adapter}"
|
79
|
+
task adapter do |t|
|
80
|
+
ENV['ARE_DB'] = adapter
|
81
|
+
Rake::Task[ 'boot' ].invoke
|
82
|
+
|
83
|
+
task = Rake::Task[ "db:test:prepare_#{adapter}" ]
|
84
|
+
begin
|
85
|
+
task = false if SchemaInfo::VERSION == SchemaInfo.find( :first ).version
|
86
|
+
rescue Exception => ex
|
87
|
+
end
|
88
|
+
task.invoke if task
|
89
|
+
|
90
|
+
system "ruby #{File.join( DIR, 'tests/run_from_gem.rb ' )} #{adapter}"
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/config/database.yml
ADDED
data/config/mysql.schema
ADDED
@@ -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;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
CREATE TABLE topics (
|
2
|
+
id serial NOT NULL,
|
3
|
+
title character varying(255) default NULL,
|
4
|
+
author_name character varying(255) default NULL,
|
5
|
+
author_email_address character varying(255) default NULL,
|
6
|
+
written_on timestamp default NULL,
|
7
|
+
bonus_time time default NULL,
|
8
|
+
last_read date default NULL,
|
9
|
+
content text,
|
10
|
+
approved bool default TRUE,
|
11
|
+
replies_count integer default 0,
|
12
|
+
parent_id serial default NULL,
|
13
|
+
type character varying(50) default NULL,
|
14
|
+
PRIMARY KEY (id)
|
15
|
+
);
|
16
|
+
|
17
|
+
CREATE TABLE projects (
|
18
|
+
id serial NOT NULL,
|
19
|
+
name character varying(100) default NULL,
|
20
|
+
type character varying(255) NOT NULL,
|
21
|
+
PRIMARY KEY (id)
|
22
|
+
);
|
23
|
+
|
24
|
+
CREATE TABLE developers (
|
25
|
+
id serial NOT NULL,
|
26
|
+
name character varying(100) default NULL,
|
27
|
+
salary integer default 70000,
|
28
|
+
created_at timestamp default NULL,
|
29
|
+
updated_at timestamp default NULL,
|
30
|
+
PRIMARY KEY (id)
|
31
|
+
);
|
32
|
+
|
33
|
+
CREATE TABLE books (
|
34
|
+
id serial NOT NULL,
|
35
|
+
title character varying(255) NOT NULL,
|
36
|
+
publisher character varying(255) NOT NULL,
|
37
|
+
author_name character varying(255) NOT NULL,
|
38
|
+
PRIMARY KEY (id)
|
39
|
+
);
|