sam / dm-www

The DataMapper Website

This URL has Read+Write access

dm-www / content / articles / datamapper_090_released.txt
100644 214 lines (193 sloc) 5.485 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
body_id: news
title: DataMapper 0.9 To Be Released on 26 May 08
created_at: 2008-05-20T20:11:24-05:00
summary: And you thought that The Great Refactoring was for naught
release_type: important
author: ssmoot, afrench
filter:
  - erb
  - textile
---
 
h1. <%= @page.title %>
 
 
As of 26 May 2008, DataMapper 0.9 will be ready for the world. It brings with it a massive overhaul of the internals of DataMapper, a shift in terminology, a dramatic bump in speed, improved code-base organization, and support for more than just database data-stores.
 
This is NOT a backwards compatible release. Code written for DataMapper 0.3 will not function with DataMapper 0.9 due to syntactical changes and library improvements.
 
REPEAT: This is NOT a backwards compatible release.
 
<table summary="Sytax Differences" cellspacing="0" cellpadding="0">
  <thead>
    <tr>
      <td colspan="3" class="pointer"><h3 style="text-align:center;">Syntax Differences</h3></td>
    </tr>
    <tr class="head">
      <td width="49%" class="pointer">DataMapper 0.3</th>
      <td width="2%" class="pointer"></th>
      <td width="49%" class="pointer">DataMapper 0.9</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
<% coderay(:lang => "ruby") do -%>
class Post < DataMapper::Base
end<% end %>
      </td>
      <td class="pointer">
        Creating A Class
      </td>
      <td>
<% coderay(:lang => "ruby") do -%>
class Post
  include DataMapper::Resource
end<% end %>
      </td>
    </tr>
    <tr>
      <td>
<% coderay(:lang => "ruby") do -%>
# Key was not mandatory
# Automatically added +id+ if missing
#
# Natural Key
property :name, :string, :key => true
#
# Composite Key
property :id, :integer, :key => true
property :slug, :string, :key => true
<% end %>
      </td>
      <td class="pointer">
        Keys
      </td>
      <td>
<% coderay(:lang => "ruby") do -%>
# keys are now mandatory
property :id, Integer, :key => true
#
# Natural Key
property :slug, String, :key => true
#
# Composite Key
property :id, Integer, :key => true
property :slug, String, :key => true
<% end %>
      </td>
    </tr>
    <tr>
      <td>
<% coderay(:lang => "ruby") do -%>
property :title, :string
property :body, :text
property :posted_on, :datetime
property :active, :boolean
<% end %>
      </td>
      <td class="pointer">
        Properties
      </td>
      <td>
<% coderay(:lang => "ruby") do -%>
property :title, String
property :body, Text
property :posted_on, Datetime
property :active, Boolean
<% end %>
      </td>
    </tr>
    <tr>
      <td>
<% coderay(:lang => "ruby") do -%>
has_many :comments
belongs_to :blog
has_and_belongs_to_many :categories
has_one :author
<% end %>
      </td>
      <td class="pointer">
        Associations
      </td>
      <td>
<% coderay(:lang => "ruby") do -%>
has 0..n, :comments
belongs_to :blog
has n, :categories => :categories_posts
has 1, :author
<% end %>
      </td>
    </tr>
    <tr>
      <td>
        <% coderay(:lang => "ruby") do -%>
Post.first :order => 'created_at desc'
Post.all
  :conditions => ['active = ?', true]
 
database.query %Q{SELECT 1}
database.execute %Q{UPDATE posts...}
        <% end %>
      </td>
      <td class="pointer">
        Finders
      </td>
      <td>
        <% coderay(:lang => "ruby") do -%>
Post.first :order => [:created_at.desc]
Post.all
  :conditions => ['active = ?', true]
 
repository(:default).adapter.query %Q{SELECT 1}
repository(:default).adapter.execute %Q{UPDATE posts...}
        <% end %>
      </td>
    </tr>
    <tr>
      <td>
        <% coderay(:lang => "ruby") do -%>
validates_presence_of :title
validates_numericality_of :rating
validates_format_of :email,
  :with => :email_address
validates_length_of :summary,
  :within => (1..100)
validates_uniqueness_of :slug
        <% end %>
      </td>
      <td class="pointer">
        Validations
      </td>
      <td>
        <% coderay(:lang => "ruby") do -%>
validates_present :title
validates_is_number :rating
validates_format :email,
  :as => :email_address
validates_length :summary,
  :in => (1..100)
validates_is_unique :slug
        <% end %>
      </td>
    </tr>
    <tr>
      <td>
        <% coderay(:lang => "ruby") do -%>
before_save :categorize
 
before_create do |post|
  # do stuff with post
end
 
# return false to abort
        <% end %>
      </td>
      <td class="pointer">Callbacks</td>
      <td>
        <% coderay(:lang => "ruby") do -%>
before :save, :categorize
 
before :create do
  # do stuff with self
end
 
# throw :halt to abort
        <% end %>
      </td>
    </tr>
  </tbody>
</table>
 
 
DM-Core now sports over 1,000 specs split between unit tests and full integration tests. If you ever have any questions about syntax, dig into the integration specs first. It's very likely your use-case is represented there.
 
DataObjects (do_mysql, do_postgres, and do_sqlite3) has gotten a performance rewrite as well, making them up to 40x faster than before in some cases.
 
h3. Pre-Release Warning
 
Though DataMapper 0.9 is stable and production ready, it represents a pre-release before 1.0, and as such, is a work in progress. If you come across ANYTHING of concern, hop on "#datamapper":irc://irc.freenode.net/#datamapper or the "mailing list":http://groups.google.com/group/datamapper, or file a bug on our "issue tracker":http://wm.lighthouseapp.com/projects/4819-datamapper. We want to hear from you!