og 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +485 -0
- data/README +35 -12
- data/Rakefile +4 -7
- data/benchmark/bench.rb +1 -1
- data/doc/AUTHORS +3 -3
- data/doc/RELEASES +153 -2
- data/doc/config.txt +0 -7
- data/doc/tutorial.txt +7 -0
- data/examples/README +5 -0
- data/examples/mysql_to_psql.rb +25 -50
- data/examples/run.rb +62 -77
- data/install.rb +1 -1
- data/lib/og.rb +45 -106
- data/lib/og/collection.rb +156 -0
- data/lib/og/entity.rb +131 -0
- data/lib/og/errors.rb +10 -15
- data/lib/og/manager.rb +115 -0
- data/lib/og/{mixins → mixin}/hierarchical.rb +43 -37
- data/lib/og/{mixins → mixin}/orderable.rb +35 -35
- data/lib/og/{mixins → mixin}/timestamped.rb +0 -6
- data/lib/og/{mixins → mixin}/tree.rb +0 -4
- data/lib/og/relation.rb +178 -0
- data/lib/og/relation/belongs_to.rb +14 -0
- data/lib/og/relation/has_many.rb +62 -0
- data/lib/og/relation/has_one.rb +17 -0
- data/lib/og/relation/joins_many.rb +69 -0
- data/lib/og/relation/many_to_many.rb +17 -0
- data/lib/og/relation/refers_to.rb +31 -0
- data/lib/og/store.rb +223 -0
- data/lib/og/store/filesys.rb +113 -0
- data/lib/og/store/madeleine.rb +4 -0
- data/lib/og/store/memory.rb +291 -0
- data/lib/og/store/mysql.rb +283 -0
- data/lib/og/store/psql.rb +238 -0
- data/lib/og/store/sql.rb +599 -0
- data/lib/og/store/sqlite.rb +190 -0
- data/lib/og/store/sqlserver.rb +262 -0
- data/lib/og/types.rb +19 -0
- data/lib/og/validation.rb +0 -4
- data/test/og/{mixins → mixin}/tc_hierarchical.rb +21 -23
- data/test/og/{mixins → mixin}/tc_orderable.rb +15 -14
- data/test/og/mixin/tc_timestamped.rb +38 -0
- data/test/og/store/tc_filesys.rb +71 -0
- data/test/og/tc_relation.rb +36 -0
- data/test/og/tc_store.rb +290 -0
- data/test/og/tc_types.rb +21 -0
- metadata +54 -40
- data/examples/mock_example.rb +0 -50
- data/lib/og/adapters/base.rb +0 -706
- data/lib/og/adapters/filesys.rb +0 -117
- data/lib/og/adapters/mysql.rb +0 -350
- data/lib/og/adapters/oracle.rb +0 -368
- data/lib/og/adapters/psql.rb +0 -272
- data/lib/og/adapters/sqlite.rb +0 -265
- data/lib/og/adapters/sqlserver.rb +0 -356
- data/lib/og/database.rb +0 -290
- data/lib/og/enchant.rb +0 -149
- data/lib/og/meta.rb +0 -407
- data/lib/og/testing/mock.rb +0 -165
- data/lib/og/typemacros.rb +0 -24
- data/test/og/adapters/tc_filesys.rb +0 -83
- data/test/og/adapters/tc_sqlite.rb +0 -86
- data/test/og/adapters/tc_sqlserver.rb +0 -96
- data/test/og/tc_automanage.rb +0 -46
- data/test/og/tc_lifecycle.rb +0 -105
- data/test/og/tc_many_to_many.rb +0 -61
- data/test/og/tc_meta.rb +0 -55
- data/test/og/tc_validation.rb +0 -89
- data/test/tc_og.rb +0 -364
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Og 0.
|
1
|
+
= Og 0.17.0 README
|
2
2
|
|
3
3
|
Og (ObjectGraph) is a powerfull object-relational mapping library. Og provides
|
4
4
|
transparent serialization of object graphs to a RDBMS
|
@@ -27,21 +27,29 @@ The library provides the following features:
|
|
27
27
|
|
28
28
|
+ Object-Relational mapping.
|
29
29
|
+ Absolutely no configuration files.
|
30
|
-
+ Multiple
|
30
|
+
+ Multiple stores (PostgreSQL, MySQL, SQLite, Oraclei, SqlServer, ..).
|
31
|
+
+ Supports non SQL stores.
|
31
32
|
+ ActiveRecord-style meta language and db aware methods.
|
32
|
-
+
|
33
|
-
+ Deserialize sql join queries to Ruby Objects
|
33
|
+
+ Deserialize to Ruby Objects.
|
34
|
+
+ Deserialize sql join queries to Ruby Objects.
|
35
|
+
+ Eager associations.
|
34
36
|
+ Serialize arbitrary ruby object graphs through YAML.
|
35
37
|
+ Connection pooling.
|
36
|
-
+ Thread safety.
|
38
|
+
+ Thread safety (temporarily dissabled).
|
37
39
|
+ SQL transactions.
|
38
|
-
+
|
40
|
+
+ Aspect oriented constructs allow interception of lifecycle callbacks.
|
39
41
|
+ Transparent support for cascading deletes for all backends.
|
40
|
-
+
|
41
|
-
+
|
42
|
-
+
|
43
|
-
|
44
|
-
|
42
|
+
+ Hierarchical structures (nested sets)
|
43
|
+
+ Works safely as part of distributed application.
|
44
|
+
+ Simple implementation.
|
45
|
+
|
46
|
+
|
47
|
+
== What's new
|
48
|
+
|
49
|
+
For information about the latest changes please consult the
|
50
|
+
file
|
51
|
+
|
52
|
+
doc/RELEASES
|
45
53
|
|
46
54
|
|
47
55
|
== Download
|
@@ -51,7 +59,7 @@ The latest version of Og can be found at
|
|
51
59
|
* http://nitro.rubyforge.org
|
52
60
|
|
53
61
|
Documentation for Og can be found in the distribution. You can find
|
54
|
-
a nice tutorial at www.rubygarden.com
|
62
|
+
a nice tutorial at www.rubygarden.com.
|
55
63
|
|
56
64
|
|
57
65
|
== Requirements
|
@@ -69,6 +77,8 @@ Og requires the following applications or libraries:
|
|
69
77
|
* Ruby-mysql
|
70
78
|
http://tmtm.org/ja/ruby/mysql/README_en.html
|
71
79
|
Ruby interface to the MySQL RDBMS.
|
80
|
+
Pure Ruby Mysql interface:
|
81
|
+
http://www.tmtm.org/ruby/mysql/
|
72
82
|
|
73
83
|
* PostgreSQL
|
74
84
|
http://www.postgres.org
|
@@ -78,6 +88,9 @@ Og requires the following applications or libraries:
|
|
78
88
|
http://www.mysql.org
|
79
89
|
Used for the Database Backend.
|
80
90
|
|
91
|
+
* SQLite
|
92
|
+
http://www.sqlite.org/download.html
|
93
|
+
|
81
94
|
Please install the required applications and libraries before continuing
|
82
95
|
with the installation of Og. Only install the libraries needed for
|
83
96
|
the backend you plan to use.
|
@@ -98,6 +111,16 @@ Then try to run the examples in the examples directory.
|
|
98
111
|
A tar.gz distribution is also available on http://www.rubyforge.com/projects/nitro.
|
99
112
|
|
100
113
|
|
114
|
+
== Examples:
|
115
|
+
|
116
|
+
Some examples can be found in the examples directory. You are also
|
117
|
+
encouraged to check out the unit tests. Especially the test:
|
118
|
+
|
119
|
+
test/og/tc_store.rb
|
120
|
+
|
121
|
+
demonstrates some advanced features of Og.
|
122
|
+
|
123
|
+
|
101
124
|
== Support
|
102
125
|
|
103
126
|
For any questions regarding Og, feel free to ask on the ruby-talk
|
data/Rakefile
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# (c) 2005 Navel, all rights reserved.
|
3
|
-
# $Id$
|
4
|
-
|
5
1
|
require 'rake/rdoctask'
|
6
2
|
require 'rake/testtask'
|
7
3
|
require 'rake/gempackagetask'
|
@@ -61,9 +57,10 @@ spec = Gem::Specification.new do |s|
|
|
61
57
|
s.description = 'An efficient and transparent Object-Relational mapping library'
|
62
58
|
|
63
59
|
s.add_dependency 'glue', "= #{s.version}"
|
64
|
-
|
65
|
-
#
|
66
|
-
#
|
60
|
+
s.add_dependency 'facets', '>= 0.7.1'
|
61
|
+
#s.add_dependency 'postgres-pr', '>= 0.3.0'
|
62
|
+
#s.add_dependency 'postgres', '>= 0.7.1'
|
63
|
+
#s.add_dependency 'sqlite3-ruby', '>= 1.0.0'
|
67
64
|
#s.add_dependency 'mysql', '>= 2.5.1'
|
68
65
|
|
69
66
|
s.required_ruby_version = '>= 1.8.2'
|
data/benchmark/bench.rb
CHANGED
data/doc/AUTHORS
CHANGED
@@ -6,14 +6,14 @@ MAIN DEVELOPER:
|
|
6
6
|
|
7
7
|
IDEAS, ADDITIONAL CODING, SUPPORT:
|
8
8
|
|
9
|
+
* Michael Neumann <mneumann@ntecs.de>
|
10
|
+
Design, additional coding and bug reports.
|
11
|
+
|
9
12
|
* Matt Bowen <matt.bowen@farweststeel.com>
|
10
13
|
Additional code and documentation.
|
11
14
|
|
12
15
|
* Anastasios Koutoumanos <ak@navel.gr>
|
13
16
|
Design, additional coding.
|
14
17
|
|
15
|
-
* Michael Neumann <mneumann@ntecs.de>
|
16
|
-
Design, additional coding and bug reports.
|
17
|
-
|
18
18
|
* Thomas Quas <tquas@yahoo.com>
|
19
19
|
Ideas, bug reports, unit tests.
|
data/doc/RELEASES
CHANGED
@@ -1,9 +1,160 @@
|
|
1
|
-
== Version 0.
|
1
|
+
== Version 0.17.0
|
2
|
+
|
3
|
+
Og Reloaded!! A totally new, clean and elegant implementation
|
4
|
+
that supports tons of new advanced features. This version should
|
5
|
+
be considered as a preview, but you really have to *try* this!
|
6
|
+
A new version, with the rest of the planned features and bug
|
7
|
+
fixes is expected shortly. Many thanks to Michael Neumann and
|
8
|
+
the other hackers on the mailing list for ideas and suggestions
|
9
|
+
that made this version possible.
|
10
|
+
|
11
|
+
Most notable additions:
|
12
|
+
|
13
|
+
* Extremely clean source code. Better names are used thorougout.
|
14
|
+
Extra care was taken to make all features more orthogonal.
|
15
|
+
|
16
|
+
* Brand new relation mechanism. The 'enchanting' of entities
|
17
|
+
(managed classes) happens in multiple passes to be more
|
18
|
+
flexible. Totaly separated graph/metadata creation and serialization
|
19
|
+
code generation. The Graph metadata can be used for advanced
|
20
|
+
scaffolding, testing and more.
|
21
|
+
|
22
|
+
* Support for fully customizable primary keys. You are no longer
|
23
|
+
forced to use xxx_oid primary keys. Appart from the extra
|
24
|
+
flexibility this feature provides this is an essential step
|
25
|
+
towards the planed 'reverse engineering' mode that will allow the
|
26
|
+
use of existing schemas with Og.
|
27
|
+
|
28
|
+
* More elegant inspection mechanism. Example:
|
29
|
+
|
30
|
+
Article.relation(:user) # => Og::BelongsTo(...)
|
31
|
+
Article.relations # => [...]
|
32
|
+
Article.properties # => [...]
|
33
|
+
|
34
|
+
* Joins_many relation, as an alias for one way, join table relations.
|
35
|
+
|
36
|
+
* Support for 'active' collections. Active collection are
|
37
|
+
synchronized with the backend Store and provide a more elegant
|
38
|
+
interface and the opportunity for 'session' caching:
|
39
|
+
|
40
|
+
article.comments << Comment.new
|
41
|
+
|
42
|
+
instead of
|
43
|
+
|
44
|
+
article.add_comment(Comment.new) # this is also allowed though.
|
45
|
+
|
46
|
+
p article.comments
|
47
|
+
p article.comments.size # the results of the first query is cached
|
48
|
+
|
49
|
+
* Eager relations.
|
50
|
+
|
51
|
+
comments = Article.comments(:include => User)
|
52
|
+
|
53
|
+
for comment in comments
|
54
|
+
p comment.user.name
|
55
|
+
end
|
56
|
+
|
57
|
+
Elegantly solves the N+1 query problem by using one join
|
58
|
+
query.
|
59
|
+
|
60
|
+
* No need for forward references when defining relations. Now,
|
61
|
+
the following code magically works:
|
62
|
+
|
63
|
+
class User
|
64
|
+
has_many Comment # works even though Comment is not defined!
|
65
|
+
end
|
66
|
+
|
67
|
+
class Comment
|
68
|
+
belongs_to User
|
69
|
+
end
|
70
|
+
|
71
|
+
* Use inflection where possible to infer missing configuration
|
72
|
+
options. For example
|
73
|
+
|
74
|
+
class Article
|
75
|
+
belongs_to User # infects relation name :user
|
76
|
+
...
|
77
|
+
|
78
|
+
* New, lean and mean Store interface. The code needed to teach
|
79
|
+
Og how to serialize objects to backend store is dramatically
|
80
|
+
reduced. The new interface is SQL agnostic, so non SQL-RDBM's
|
81
|
+
stores are possible.
|
82
|
+
|
83
|
+
* SQL agnostic querying interface, compatible with non-sql
|
84
|
+
Stores. Here is an example:
|
85
|
+
|
86
|
+
Article.find(
|
87
|
+
:condition => 'hits > 2 AND rate > 3',
|
88
|
+
:order => 'title',
|
89
|
+
:offset => 30,
|
90
|
+
:limit => 10
|
91
|
+
)
|
92
|
+
|
93
|
+
* More elegant (and non-sql store compatible) way for selective
|
94
|
+
updates:
|
95
|
+
|
96
|
+
article.title = 'Changed'
|
97
|
+
article.hits += 1
|
98
|
+
article.update(:title, :hits)
|
99
|
+
|
100
|
+
* New, in-memory store that support all features. This is a pure
|
101
|
+
ruby solution useful for experimentation. It will also serve
|
102
|
+
as the base for the forthcoming madeleine Store implementation.
|
103
|
+
|
104
|
+
* Allow for multiple stores in one application. A great example,
|
105
|
+
mysql_to_psql is provided. This example uses Og's powerfull
|
106
|
+
features to automatically convert a Mysql database to a
|
107
|
+
PostgreSQL database. Database migration was never easier.
|
108
|
+
|
109
|
+
* Uses the excellent Facets utility collection to further
|
110
|
+
clenup and minimize the code.
|
111
|
+
|
112
|
+
* Managed classes or Entities should include the EntityMixin
|
113
|
+
or extend the Entity class. Example:
|
114
|
+
|
115
|
+
class Article < Entity
|
116
|
+
..
|
117
|
+
end
|
118
|
+
|
119
|
+
class Article
|
120
|
+
include EntityMixin
|
121
|
+
end
|
122
|
+
|
123
|
+
This is done to avoid the Module module like in earlier
|
124
|
+
versions of Og. However, Og is can infer the need to include
|
125
|
+
the Managed mixin in typical cases:
|
126
|
+
|
127
|
+
class Article
|
128
|
+
property :title, String
|
129
|
+
# when a property is defined Og automatically converts the
|
130
|
+
# class to an Entity
|
131
|
+
end
|
132
|
+
|
133
|
+
class Article < AnExistingManagedEntity
|
134
|
+
# also includes the mixin
|
135
|
+
...
|
136
|
+
|
137
|
+
class Article
|
138
|
+
include AModuleThatDefinesProperties
|
139
|
+
...
|
140
|
+
|
141
|
+
* Improved support for og_delete interception.
|
142
|
+
|
143
|
+
* Support for nested transactions.
|
144
|
+
|
145
|
+
* Many, many smaller features and changes.
|
146
|
+
|
147
|
+
Check out the file test/og/tc_store.rb for a demonstration of
|
148
|
+
the new features. The stores for Oracle and SqlServer are not
|
149
|
+
converted yet.
|
150
|
+
|
151
|
+
|
152
|
+
== Version 0.16.0 was released on 15/04/2005.
|
2
153
|
|
3
154
|
A snapshot of the latest developments. Many, many subtle improvements,
|
4
155
|
new features and a major cleanup of the source code.
|
5
156
|
|
6
|
-
Most notable
|
157
|
+
Most notable additions:
|
7
158
|
|
8
159
|
* Aspect Oriented Programming support. This new system
|
9
160
|
is used to reimplement features such as Controller filters,
|
data/doc/config.txt
CHANGED
@@ -14,13 +14,6 @@ applications/sites on a single database.
|
|
14
14
|
If true, use Ruby's advanced introspection capabilities to
|
15
15
|
automatically manage classes that define properties.
|
16
16
|
|
17
|
-
=== Og.enchant_managed_classes = true
|
18
|
-
|
19
|
-
If true, the library automatically 'enchants' managed classes.
|
20
|
-
In enchant mode, special db aware methods are added to
|
21
|
-
managed classes and instances. If false, Og enchants only classes
|
22
|
-
that define properties.
|
23
|
-
|
24
17
|
=== Og.create_schema = true
|
25
18
|
|
26
19
|
If set to true, Og attempts to recreate the database schema
|
data/doc/tutorial.txt
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
= Og Tutorial
|
2
2
|
|
3
|
+
=== WARNING
|
4
|
+
|
5
|
+
This tutorial is not updated for the latest code. However it is
|
6
|
+
a nice read to understand the spirit and feature of Og. Please
|
7
|
+
consult the API for the latest more advanced features of Og.
|
8
|
+
|
9
|
+
|
3
10
|
=== Introduction
|
4
11
|
|
5
12
|
Ruby is a wonderful object oriented language featuring a well
|
data/examples/README
CHANGED
data/examples/mysql_to_psql.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# =
|
1
|
+
# = Mysql to PostgreSQL migration example.
|
2
2
|
#
|
3
3
|
# A simple example to demonstrate the flexibility of
|
4
4
|
# Og. Two connections to different databases are
|
@@ -6,71 +6,46 @@
|
|
6
6
|
# to a PostgreSQL database.
|
7
7
|
#
|
8
8
|
# Og makes it easier to switch to a REAL database :)
|
9
|
-
#
|
10
|
-
# * George Moschovitis <gm@navel.gr>
|
11
|
-
# (c) 2004-2005 Navel, all rights reserved.
|
12
|
-
# $Id: mysql_to_psql.rb 1 2005-04-11 11:04:30Z gmosx $
|
13
|
-
|
14
|
-
raise 'WARNING, this example does not work yet, for the moment ' +
|
15
|
-
'just have a look at the source code.'
|
16
9
|
|
17
10
|
require 'og'
|
18
11
|
|
19
|
-
# An example managed object.
|
20
|
-
# Looks like an ordinary Ruby object.
|
21
|
-
|
22
|
-
class Article
|
23
|
-
prop_accessor :name, :body, String
|
24
|
-
|
25
|
-
def initialize(name = nil, body = nil)
|
26
|
-
@name, @body = name, body
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
12
|
# Configure databases.
|
31
13
|
|
32
14
|
psql_config = {
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
15
|
+
:destroy => true,
|
16
|
+
:name => 'test',
|
17
|
+
:store => 'psql',
|
36
18
|
:user => 'postgres',
|
37
|
-
:password => 'navelrulez'
|
38
|
-
:connection_count => 1
|
19
|
+
:password => 'navelrulez'
|
39
20
|
}
|
40
21
|
|
41
22
|
mysql_config = {
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:user => 'postgres',
|
46
|
-
:password => 'navelrulez',
|
47
|
-
:connection_count => 1
|
48
|
-
}
|
49
|
-
=begin
|
50
|
-
mysql_config = {
|
51
|
-
:address => 'localhost',
|
52
|
-
:database => 'test',
|
53
|
-
:backend => 'mysql',
|
23
|
+
:destroy => true,
|
24
|
+
:name => 'test',
|
25
|
+
:store => 'mysql',
|
54
26
|
:user => 'root',
|
55
|
-
:password => 'navelrulez'
|
56
|
-
:connection_count => 1
|
27
|
+
:password => 'navelrulez'
|
57
28
|
}
|
58
|
-
=end
|
59
29
|
|
60
|
-
#
|
61
|
-
# earlier executions.
|
30
|
+
# Initialize Og.
|
62
31
|
|
63
|
-
Og
|
64
|
-
Og
|
32
|
+
psql = Og.connect(psql_config)
|
33
|
+
mysql = Og.connect(mysql_config)
|
65
34
|
|
66
|
-
#
|
35
|
+
# An example managed object.
|
36
|
+
# Looks like an ordinary Ruby object.
|
67
37
|
|
68
|
-
|
69
|
-
|
38
|
+
class Article
|
39
|
+
property :name, :body, String
|
40
|
+
|
41
|
+
def initialize(name = nil, body = nil)
|
42
|
+
@name, @body = name, body
|
43
|
+
end
|
44
|
+
end
|
70
45
|
|
71
46
|
# First populate the mysql database.
|
72
47
|
|
73
|
-
|
48
|
+
mysql.manage(Article)
|
74
49
|
|
75
50
|
a1 = Article.create('name1', 'body1')
|
76
51
|
a1 = Article.create('name1', 'body1')
|
@@ -82,15 +57,15 @@ articles = Article.all
|
|
82
57
|
|
83
58
|
# Switch to PostgreSQL.
|
84
59
|
|
85
|
-
|
60
|
+
psql.manage(Article)
|
86
61
|
|
87
62
|
# Store all articles.
|
88
63
|
|
89
64
|
for article in articles
|
90
|
-
article.
|
65
|
+
article.insert
|
91
66
|
end
|
92
67
|
|
93
68
|
# Fetch an article from PostgreSQL
|
94
69
|
# as an example. Lookup by name.
|
95
70
|
|
96
|
-
article = Article
|
71
|
+
article = Article.find_by_name('name1')
|