viking-sequel 3.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. data/CHANGELOG +3134 -0
  2. data/COPYING +19 -0
  3. data/README.rdoc +723 -0
  4. data/Rakefile +193 -0
  5. data/bin/sequel +196 -0
  6. data/doc/advanced_associations.rdoc +644 -0
  7. data/doc/cheat_sheet.rdoc +218 -0
  8. data/doc/dataset_basics.rdoc +106 -0
  9. data/doc/dataset_filtering.rdoc +158 -0
  10. data/doc/opening_databases.rdoc +296 -0
  11. data/doc/prepared_statements.rdoc +104 -0
  12. data/doc/reflection.rdoc +84 -0
  13. data/doc/release_notes/1.0.txt +38 -0
  14. data/doc/release_notes/1.1.txt +143 -0
  15. data/doc/release_notes/1.3.txt +101 -0
  16. data/doc/release_notes/1.4.0.txt +53 -0
  17. data/doc/release_notes/1.5.0.txt +155 -0
  18. data/doc/release_notes/2.0.0.txt +298 -0
  19. data/doc/release_notes/2.1.0.txt +271 -0
  20. data/doc/release_notes/2.10.0.txt +328 -0
  21. data/doc/release_notes/2.11.0.txt +215 -0
  22. data/doc/release_notes/2.12.0.txt +534 -0
  23. data/doc/release_notes/2.2.0.txt +253 -0
  24. data/doc/release_notes/2.3.0.txt +88 -0
  25. data/doc/release_notes/2.4.0.txt +106 -0
  26. data/doc/release_notes/2.5.0.txt +137 -0
  27. data/doc/release_notes/2.6.0.txt +157 -0
  28. data/doc/release_notes/2.7.0.txt +166 -0
  29. data/doc/release_notes/2.8.0.txt +171 -0
  30. data/doc/release_notes/2.9.0.txt +97 -0
  31. data/doc/release_notes/3.0.0.txt +221 -0
  32. data/doc/release_notes/3.1.0.txt +406 -0
  33. data/doc/release_notes/3.10.0.txt +286 -0
  34. data/doc/release_notes/3.2.0.txt +268 -0
  35. data/doc/release_notes/3.3.0.txt +192 -0
  36. data/doc/release_notes/3.4.0.txt +325 -0
  37. data/doc/release_notes/3.5.0.txt +510 -0
  38. data/doc/release_notes/3.6.0.txt +366 -0
  39. data/doc/release_notes/3.7.0.txt +179 -0
  40. data/doc/release_notes/3.8.0.txt +151 -0
  41. data/doc/release_notes/3.9.0.txt +233 -0
  42. data/doc/schema.rdoc +36 -0
  43. data/doc/sharding.rdoc +113 -0
  44. data/doc/virtual_rows.rdoc +205 -0
  45. data/lib/sequel.rb +1 -0
  46. data/lib/sequel/adapters/ado.rb +90 -0
  47. data/lib/sequel/adapters/ado/mssql.rb +30 -0
  48. data/lib/sequel/adapters/amalgalite.rb +176 -0
  49. data/lib/sequel/adapters/db2.rb +139 -0
  50. data/lib/sequel/adapters/dbi.rb +113 -0
  51. data/lib/sequel/adapters/do.rb +188 -0
  52. data/lib/sequel/adapters/do/mysql.rb +49 -0
  53. data/lib/sequel/adapters/do/postgres.rb +91 -0
  54. data/lib/sequel/adapters/do/sqlite.rb +40 -0
  55. data/lib/sequel/adapters/firebird.rb +283 -0
  56. data/lib/sequel/adapters/informix.rb +77 -0
  57. data/lib/sequel/adapters/jdbc.rb +587 -0
  58. data/lib/sequel/adapters/jdbc/as400.rb +58 -0
  59. data/lib/sequel/adapters/jdbc/h2.rb +133 -0
  60. data/lib/sequel/adapters/jdbc/mssql.rb +57 -0
  61. data/lib/sequel/adapters/jdbc/mysql.rb +78 -0
  62. data/lib/sequel/adapters/jdbc/oracle.rb +50 -0
  63. data/lib/sequel/adapters/jdbc/postgresql.rb +108 -0
  64. data/lib/sequel/adapters/jdbc/sqlite.rb +55 -0
  65. data/lib/sequel/adapters/mysql.rb +421 -0
  66. data/lib/sequel/adapters/odbc.rb +143 -0
  67. data/lib/sequel/adapters/odbc/mssql.rb +42 -0
  68. data/lib/sequel/adapters/openbase.rb +64 -0
  69. data/lib/sequel/adapters/oracle.rb +131 -0
  70. data/lib/sequel/adapters/postgres.rb +504 -0
  71. data/lib/sequel/adapters/shared/mssql.rb +490 -0
  72. data/lib/sequel/adapters/shared/mysql.rb +498 -0
  73. data/lib/sequel/adapters/shared/oracle.rb +195 -0
  74. data/lib/sequel/adapters/shared/postgres.rb +830 -0
  75. data/lib/sequel/adapters/shared/progress.rb +44 -0
  76. data/lib/sequel/adapters/shared/sqlite.rb +389 -0
  77. data/lib/sequel/adapters/sqlite.rb +224 -0
  78. data/lib/sequel/adapters/utils/stored_procedures.rb +84 -0
  79. data/lib/sequel/connection_pool.rb +99 -0
  80. data/lib/sequel/connection_pool/sharded_single.rb +84 -0
  81. data/lib/sequel/connection_pool/sharded_threaded.rb +211 -0
  82. data/lib/sequel/connection_pool/single.rb +29 -0
  83. data/lib/sequel/connection_pool/threaded.rb +150 -0
  84. data/lib/sequel/core.rb +293 -0
  85. data/lib/sequel/core_sql.rb +241 -0
  86. data/lib/sequel/database.rb +1079 -0
  87. data/lib/sequel/database/schema_generator.rb +327 -0
  88. data/lib/sequel/database/schema_methods.rb +203 -0
  89. data/lib/sequel/database/schema_sql.rb +320 -0
  90. data/lib/sequel/dataset.rb +32 -0
  91. data/lib/sequel/dataset/actions.rb +441 -0
  92. data/lib/sequel/dataset/features.rb +86 -0
  93. data/lib/sequel/dataset/graph.rb +254 -0
  94. data/lib/sequel/dataset/misc.rb +119 -0
  95. data/lib/sequel/dataset/mutation.rb +64 -0
  96. data/lib/sequel/dataset/prepared_statements.rb +227 -0
  97. data/lib/sequel/dataset/query.rb +709 -0
  98. data/lib/sequel/dataset/sql.rb +996 -0
  99. data/lib/sequel/exceptions.rb +51 -0
  100. data/lib/sequel/extensions/blank.rb +43 -0
  101. data/lib/sequel/extensions/inflector.rb +242 -0
  102. data/lib/sequel/extensions/looser_typecasting.rb +21 -0
  103. data/lib/sequel/extensions/migration.rb +239 -0
  104. data/lib/sequel/extensions/named_timezones.rb +61 -0
  105. data/lib/sequel/extensions/pagination.rb +100 -0
  106. data/lib/sequel/extensions/pretty_table.rb +82 -0
  107. data/lib/sequel/extensions/query.rb +52 -0
  108. data/lib/sequel/extensions/schema_dumper.rb +271 -0
  109. data/lib/sequel/extensions/sql_expr.rb +122 -0
  110. data/lib/sequel/extensions/string_date_time.rb +46 -0
  111. data/lib/sequel/extensions/thread_local_timezones.rb +48 -0
  112. data/lib/sequel/metaprogramming.rb +9 -0
  113. data/lib/sequel/model.rb +120 -0
  114. data/lib/sequel/model/associations.rb +1514 -0
  115. data/lib/sequel/model/base.rb +1069 -0
  116. data/lib/sequel/model/default_inflections.rb +45 -0
  117. data/lib/sequel/model/errors.rb +39 -0
  118. data/lib/sequel/model/exceptions.rb +21 -0
  119. data/lib/sequel/model/inflections.rb +162 -0
  120. data/lib/sequel/model/plugins.rb +70 -0
  121. data/lib/sequel/plugins/active_model.rb +59 -0
  122. data/lib/sequel/plugins/association_dependencies.rb +103 -0
  123. data/lib/sequel/plugins/association_proxies.rb +41 -0
  124. data/lib/sequel/plugins/boolean_readers.rb +53 -0
  125. data/lib/sequel/plugins/caching.rb +141 -0
  126. data/lib/sequel/plugins/class_table_inheritance.rb +214 -0
  127. data/lib/sequel/plugins/composition.rb +138 -0
  128. data/lib/sequel/plugins/force_encoding.rb +72 -0
  129. data/lib/sequel/plugins/hook_class_methods.rb +126 -0
  130. data/lib/sequel/plugins/identity_map.rb +116 -0
  131. data/lib/sequel/plugins/instance_filters.rb +98 -0
  132. data/lib/sequel/plugins/instance_hooks.rb +57 -0
  133. data/lib/sequel/plugins/lazy_attributes.rb +77 -0
  134. data/lib/sequel/plugins/many_through_many.rb +208 -0
  135. data/lib/sequel/plugins/nested_attributes.rb +206 -0
  136. data/lib/sequel/plugins/optimistic_locking.rb +81 -0
  137. data/lib/sequel/plugins/rcte_tree.rb +281 -0
  138. data/lib/sequel/plugins/schema.rb +66 -0
  139. data/lib/sequel/plugins/serialization.rb +166 -0
  140. data/lib/sequel/plugins/single_table_inheritance.rb +74 -0
  141. data/lib/sequel/plugins/subclasses.rb +45 -0
  142. data/lib/sequel/plugins/tactical_eager_loading.rb +61 -0
  143. data/lib/sequel/plugins/timestamps.rb +87 -0
  144. data/lib/sequel/plugins/touch.rb +118 -0
  145. data/lib/sequel/plugins/typecast_on_load.rb +72 -0
  146. data/lib/sequel/plugins/validation_class_methods.rb +405 -0
  147. data/lib/sequel/plugins/validation_helpers.rb +223 -0
  148. data/lib/sequel/sql.rb +1020 -0
  149. data/lib/sequel/timezones.rb +161 -0
  150. data/lib/sequel/version.rb +12 -0
  151. data/lib/sequel_core.rb +1 -0
  152. data/lib/sequel_model.rb +1 -0
  153. data/spec/adapters/firebird_spec.rb +407 -0
  154. data/spec/adapters/informix_spec.rb +97 -0
  155. data/spec/adapters/mssql_spec.rb +403 -0
  156. data/spec/adapters/mysql_spec.rb +1019 -0
  157. data/spec/adapters/oracle_spec.rb +286 -0
  158. data/spec/adapters/postgres_spec.rb +969 -0
  159. data/spec/adapters/spec_helper.rb +51 -0
  160. data/spec/adapters/sqlite_spec.rb +432 -0
  161. data/spec/core/connection_pool_spec.rb +808 -0
  162. data/spec/core/core_sql_spec.rb +417 -0
  163. data/spec/core/database_spec.rb +1662 -0
  164. data/spec/core/dataset_spec.rb +3827 -0
  165. data/spec/core/expression_filters_spec.rb +595 -0
  166. data/spec/core/object_graph_spec.rb +296 -0
  167. data/spec/core/schema_generator_spec.rb +159 -0
  168. data/spec/core/schema_spec.rb +830 -0
  169. data/spec/core/spec_helper.rb +56 -0
  170. data/spec/core/version_spec.rb +7 -0
  171. data/spec/extensions/active_model_spec.rb +76 -0
  172. data/spec/extensions/association_dependencies_spec.rb +127 -0
  173. data/spec/extensions/association_proxies_spec.rb +50 -0
  174. data/spec/extensions/blank_spec.rb +67 -0
  175. data/spec/extensions/boolean_readers_spec.rb +92 -0
  176. data/spec/extensions/caching_spec.rb +250 -0
  177. data/spec/extensions/class_table_inheritance_spec.rb +252 -0
  178. data/spec/extensions/composition_spec.rb +194 -0
  179. data/spec/extensions/force_encoding_spec.rb +117 -0
  180. data/spec/extensions/hook_class_methods_spec.rb +470 -0
  181. data/spec/extensions/identity_map_spec.rb +202 -0
  182. data/spec/extensions/inflector_spec.rb +181 -0
  183. data/spec/extensions/instance_filters_spec.rb +55 -0
  184. data/spec/extensions/instance_hooks_spec.rb +133 -0
  185. data/spec/extensions/lazy_attributes_spec.rb +153 -0
  186. data/spec/extensions/looser_typecasting_spec.rb +39 -0
  187. data/spec/extensions/many_through_many_spec.rb +884 -0
  188. data/spec/extensions/migration_spec.rb +332 -0
  189. data/spec/extensions/named_timezones_spec.rb +72 -0
  190. data/spec/extensions/nested_attributes_spec.rb +396 -0
  191. data/spec/extensions/optimistic_locking_spec.rb +100 -0
  192. data/spec/extensions/pagination_spec.rb +99 -0
  193. data/spec/extensions/pretty_table_spec.rb +91 -0
  194. data/spec/extensions/query_spec.rb +85 -0
  195. data/spec/extensions/rcte_tree_spec.rb +205 -0
  196. data/spec/extensions/schema_dumper_spec.rb +357 -0
  197. data/spec/extensions/schema_spec.rb +127 -0
  198. data/spec/extensions/serialization_spec.rb +209 -0
  199. data/spec/extensions/single_table_inheritance_spec.rb +96 -0
  200. data/spec/extensions/spec_helper.rb +91 -0
  201. data/spec/extensions/sql_expr_spec.rb +89 -0
  202. data/spec/extensions/string_date_time_spec.rb +93 -0
  203. data/spec/extensions/subclasses_spec.rb +52 -0
  204. data/spec/extensions/tactical_eager_loading_spec.rb +65 -0
  205. data/spec/extensions/thread_local_timezones_spec.rb +45 -0
  206. data/spec/extensions/timestamps_spec.rb +150 -0
  207. data/spec/extensions/touch_spec.rb +155 -0
  208. data/spec/extensions/typecast_on_load_spec.rb +69 -0
  209. data/spec/extensions/validation_class_methods_spec.rb +984 -0
  210. data/spec/extensions/validation_helpers_spec.rb +438 -0
  211. data/spec/integration/associations_test.rb +281 -0
  212. data/spec/integration/database_test.rb +26 -0
  213. data/spec/integration/dataset_test.rb +963 -0
  214. data/spec/integration/eager_loader_test.rb +734 -0
  215. data/spec/integration/model_test.rb +130 -0
  216. data/spec/integration/plugin_test.rb +814 -0
  217. data/spec/integration/prepared_statement_test.rb +213 -0
  218. data/spec/integration/schema_test.rb +361 -0
  219. data/spec/integration/spec_helper.rb +73 -0
  220. data/spec/integration/timezone_test.rb +55 -0
  221. data/spec/integration/transaction_test.rb +122 -0
  222. data/spec/integration/type_test.rb +96 -0
  223. data/spec/model/association_reflection_spec.rb +175 -0
  224. data/spec/model/associations_spec.rb +2633 -0
  225. data/spec/model/base_spec.rb +418 -0
  226. data/spec/model/dataset_methods_spec.rb +78 -0
  227. data/spec/model/eager_loading_spec.rb +1391 -0
  228. data/spec/model/hooks_spec.rb +240 -0
  229. data/spec/model/inflector_spec.rb +26 -0
  230. data/spec/model/model_spec.rb +593 -0
  231. data/spec/model/plugins_spec.rb +236 -0
  232. data/spec/model/record_spec.rb +1500 -0
  233. data/spec/model/spec_helper.rb +97 -0
  234. data/spec/model/validations_spec.rb +153 -0
  235. data/spec/rcov.opts +6 -0
  236. data/spec/spec_config.rb.example +10 -0
  237. metadata +346 -0
@@ -0,0 +1,192 @@
1
+ New Features
2
+ ------------
3
+
4
+ * An association_proxies plugin has been added. This is not a
5
+ full-blown proxy implementation, but it allows you to write code
6
+ such as:
7
+
8
+ artist.albums.filter{num_tracks > 10}
9
+
10
+ Without the plugin, you have to call filter specifically on the
11
+ association's dataset:
12
+
13
+ artist.albums_dataset.filter{num_tracks > 10}
14
+
15
+ The plugin works by proxying array methods to the array of
16
+ associated objects, and all other methods to the association's
17
+ dataset. This results in the following behavior:
18
+
19
+ # Will load the associated objects (unless they are already
20
+ # cached), and return the length of the array
21
+ artist.albums.length
22
+
23
+ # Will issue an SQL query with COUNT (even if the association
24
+ # is already cached), and return the result
25
+ artist.albums.count
26
+
27
+ * The add_*/remove_*/remove_all_* association methods now take
28
+ additional arguments that are passed down to the
29
+ _add_*/_remove_*/_remove_all_* methods. One of the things this
30
+ allows you to do is update additional columns in join tables for
31
+ many_to_many associations:
32
+
33
+ class Album
34
+ many_to_many :artists
35
+ def _add_artist(artist, values={})
36
+ DB[:albums_artists].
37
+ insert(values.merge(:album_id=>id,
38
+ :artist_id=>artist.id))
39
+ end
40
+ end
41
+
42
+ album = Album[1]
43
+ artist1 = Artist[2]
44
+ artist2 = Artist[3]
45
+ album.add_artist(artist1, :relationship=>'composer')
46
+ album.add_artist(artist2, :relationship=>'arranger')
47
+
48
+ * The JDBC adapter now accepts a :convert_types option to turn off
49
+ Java type conversion. The option is true by default for
50
+ backwards compatibility and correctness, but can be set to false
51
+ to double performance. The option can be set at the database
52
+ and dataset levels:
53
+
54
+ DB = Sequel.jdbc('jdbc:postgresql://host/database',
55
+ :convert_types=>false)
56
+ DB.convert_types = true
57
+ ds = DB[:table]
58
+ ds.convert_types = false
59
+
60
+ * Dataset#from_self now takes an option hash and respects an
61
+ :alias option, giving the table alias to use.
62
+
63
+ * Dataset#unlimited was added, similar to unfiltered and unordered.
64
+
65
+ * SQL::WindowFunction is now a subclass of SQL::GenericExpression,
66
+ so you can alias it and treat it like any other SQL::Function.
67
+
68
+ Other Improvements
69
+ ------------------
70
+
71
+ * Microsoft SQL Server support is much, much better in Sequel 3.3.0
72
+ than in previous versions. Support is pretty good with the ODBC,
73
+ ADO, and JDBC adapters, close to the level of support for
74
+ PostreSQL, MySQL, SQLite, and H2. Improvements are too numerous
75
+ to list, but here are some highlights:
76
+
77
+ * Dataset#insert now returns the primary key (identity field), so
78
+ it can be used easier with models.
79
+
80
+ * Transactions can now use savepoints (except on ADO).
81
+
82
+ * Offsets are supported when using SQL Server 2005 or 2008, using
83
+ a ROW_NUMBER window function. However, you must specify an
84
+ order for your dataset (which you probably are already doing if
85
+ you are using offsets).
86
+
87
+ * Schema parsing has been implemented, though it doesn't support
88
+ primary key parsing (except on JDBC, since the JDBC support is
89
+ used there).
90
+
91
+ * The SQL syntax Sequel uses is now much more compatible, and
92
+ most schema modification methods and database types now work
93
+ correctly.
94
+
95
+ * The ADO and ODBC adapters both work much better now. The ADO
96
+ adapter no longer attempts to use transactions, since I've found
97
+ that ADO does not give a stable native connection (and hence
98
+ transactions weren't possible). I strongly recommend against
99
+ using the ADO adapter in production.
100
+
101
+ * The H2 JDBC subadapter now supports rename_column, set_column_null,
102
+ set_column_type, and add_foreign_key.
103
+
104
+ * Altering a columns type, null status, or default is now supported
105
+ on SQLite. You can also add primary keys and unique columns.
106
+
107
+ * Both the ADO and ODBC adapters now catch the native exception
108
+ classes and raise Sequel::DatabaseErrors.
109
+
110
+ * Model classes now default to associating to other classes in the
111
+ same scope. This makes it easier to use namespaced models.
112
+
113
+ * The schema parser and schema dumper now support the following
114
+ types: nchar, nvarchar, ntext, smalldatetime, smallmoney, binary,
115
+ and varbinary.
116
+
117
+ * You can now specify the null status for a column using :allow_null
118
+ in addition to :null. This is to make it easier to use the
119
+ table creation methods with the results of the schema parser.
120
+
121
+ * Renaming a NOT NULL column without a default now works on MySQL.
122
+
123
+ * Model class initialization now raises an exception if there is a
124
+ problem connecting to the database.
125
+
126
+ * Connection pool performance has been increased slightly.
127
+
128
+ * The literal_time method in the ODBC adapter has been fixed.
129
+
130
+ * An unlikely but potential bug in the MySQL adapter has been fixed.
131
+
132
+ Backwards Compatibility
133
+ -----------------------
134
+
135
+ * The convert_tinyint_to_bool setting moved from the main Sequel
136
+ module to the Sequel::MySQL module. The native MySQL adapter is
137
+ the only adapter that converted tinyint columns to booleans when
138
+ the rows are returned, so you can only use the setting with the
139
+ native MySQL adapter.
140
+
141
+ Additionally, the setting's behavior has changed. When parsing
142
+ the schema, now only tinyint(1) columns are now considered as
143
+ boolean, instead of all tinyint columns. This allows you to use
144
+ tinyint(4) columns for storing small integers and tinyint(1)
145
+ columns as booleans, and not have the schema parsing support
146
+ consider the tinyint(4) columns as booleans. Unfortunately,
147
+ due to limitations in the native MySQL driver, all tinyint
148
+ column values are converted to booleans upon retrieval, not just
149
+ tinyint(1) column values.
150
+
151
+ Unfortunately, the previous Sequel behavior was to use the
152
+ default tinyint size (tinyint(4)) when creating boolean columns
153
+ (using the TrueClass or FalseClass generic types). If you were
154
+ using the generic type support to create the columns, you should
155
+ modify your database to change the column type from tinyint(4) to
156
+ tinyint(1).
157
+
158
+ If you use MySQL with tinyint columns, these changes have the
159
+ potential to break applications. Care should be taken when
160
+ upgrading if these changes apply to you.
161
+
162
+ * Model classes now default to associating to other classes in the
163
+ same scope. It's highly unlikely anyone was relying on the
164
+ previous behavior, but if you have a model inside a module that
165
+ you are associating to a model outside of a module, you now need
166
+ to specify the associated class using the :class option.
167
+
168
+ * Model#save no longer includes the primary key fields in the SET
169
+ clause of the UPDATE query, only in the WHERE clause. I'm not
170
+ sure if this affects backwards compatibility of production code,
171
+ but it can break tests that expect specific SQL.
172
+
173
+ * Behavior to handle empty identifiers has now been standardized.
174
+ If any database adapter returns an empty identifier, Sequel will
175
+ use 'untitled' as the identifier. This can break backwards
176
+ compatibility if the adapter previously used another default and
177
+ you were relying on that default. This was necessary to fix any
178
+ possible "interning empty string" exceptions.
179
+
180
+ * On MSSQL, Sequel now uses the datetime type instead of the
181
+ timestamp type for generic DateTimes. It now uses bit for the
182
+ TrueClass and FalseClass generic types, and image for the File
183
+ generic type.
184
+
185
+ * Sequel now unescapes URL parts:
186
+
187
+ Sequel.connect(ado:///db?host=server%5cinstance)
188
+
189
+ However, this can break backward compatibility if you previously
190
+ expected it not to be unescaped.
191
+
192
+ * The columns_for private SQLite Database method has been removed.
@@ -0,0 +1,325 @@
1
+ New Plugins
2
+ -----------
3
+
4
+ * A nested_attributes plugin was added allowing you to modify
5
+ associated objects directly through a model object, similar to
6
+ ActiveRecord's Nested Attributes.
7
+
8
+ Artist.plugin :nested_attributes
9
+ Artist.one_to_many :albums
10
+ Artist.nested_attributes :albums
11
+ a = Artist.new(:name=>'YJM',
12
+ :albums_attributes=>[{:name=>'RF'}, {:name=>'MO'}])
13
+ # No database activity yet
14
+
15
+ a.save # Saves artist and both albums
16
+ a.albums.map{|x| x.name} # ['RF', 'MO']
17
+
18
+ It takes most of the same options as ActiveRecord, as well as a
19
+ a few additional options:
20
+
21
+ * :destroy - Allow destruction of nested records.
22
+ * :limit - For *_to_many associations, a limit on the number of
23
+ records that will be processed, to prevent denial of service
24
+ attacks.
25
+ * :remove - Allow disassociation of nested records (can remove the
26
+ associated object from the parent object, but not destroy the
27
+ associated object).
28
+ * :strict - Set to false to not raise an error message if a primary
29
+ key is provided in a record, but it doesn't match an existing
30
+ associated object.
31
+
32
+ If a block is provided, it is passed each nested attribute hash.
33
+ If the hash should be ignored, the block should return anything
34
+ except false or nil.
35
+
36
+ * A timestamps plugin was added for automatically adding
37
+ before_create and before_update hooks for setting values on
38
+ timestamp columns. There are a couple of existing external
39
+ plugins that handle timestamps, but the implementations are
40
+ suboptimal. The new built-in plugin supports the following
41
+ options (with the default in parentheses):
42
+
43
+ * :create - The field to hold the create timestamp (:created_at)
44
+ * :force - Whether to overwrite an existing create timestamp
45
+ (false)
46
+ * :update - The field to hold the update timestamp (:updated_at)
47
+ * :update_on_create - Whether to set the update timestamp to the
48
+ create timestamp when creating (false)
49
+
50
+ * An instance_hooks plugin was added for adding hooks to specific
51
+ w
52
+ model instances:
53
+
54
+ obj = Model.new
55
+ obj.after_save_hook{do_something}
56
+ obj.save # calls do_something after the obj has been saved
57
+
58
+ All of the standard hooks are supported, except for
59
+ after_initialize. Instance level before hooks are executed in
60
+ reverse order of addition before calling super. Instance level
61
+ after hooks are executed in order of addition after calling super.
62
+ If any of the instance level before hook blocks return false, no
63
+ more instance level before hooks are called and false is returned.
64
+
65
+ Instance level hooks are cleared when the object is saved
66
+ successfully.
67
+
68
+ * A boolean_readers plugin was added for creating attribute? methods
69
+ for boolean columns. This can provide a nicer API:
70
+
71
+ obj = Model[1]
72
+ obj.active # Sequel default column reader
73
+ obj.active? # Using the boolean_readers plugin
74
+
75
+ You can provide a block when loading the plugin to change the
76
+ criteria used to determine if the column is boolean:
77
+
78
+ Sequel::Model.plugin(:boolean_readers) do |c|
79
+ db_schema[c][:db_type] =~ /\Atinyint/
80
+ end
81
+
82
+ This may be useful if you are using MySQL and have some tinyint
83
+ columns that represent booleans and others that represent integers.
84
+ You can turn the convert_tinyint_to_bool setting off and use the
85
+ attribute methods for the integer value and the attribute? methods
86
+ for the boolean value.
87
+
88
+ Other New Features
89
+ ------------------
90
+
91
+ * Sequel now has support for converting Time/DateTime to local or UTC
92
+ time upon storage, retrieval, or typecasting.
93
+
94
+ There are three different timezone settings:
95
+
96
+ * Sequel.database_timezone - The timezone that timestamps use in
97
+ the database. If the database returns a time without an offset,
98
+ it is assumed to be in this timezone.
99
+
100
+ * Sequel.typecast_timezone - Similar to database_timezone, but used
101
+ for typecasting data from a source other than the database. This
102
+ is currently only used by the model typecasting code.
103
+
104
+ * Sequel.application_timezone - The timezone that the application
105
+ wants to deal with. All Time/DateTime objects are converted into
106
+ this timezone upon retrieval from the database.
107
+
108
+ Unlike most things in Sequel, these are only global settings, you
109
+ cannot change them per database. There are only three valid
110
+ timezone settings:
111
+
112
+ * nil (the default) - Don't do any timezone conversion. This is
113
+ the historical behavior.
114
+
115
+ * :local - Convert to local time/Consider time to be in local time.
116
+
117
+ * :utc - Convert to UTC/Consider time to be in UTC.
118
+
119
+ So if you want to store times in the database as UTC, but deal with
120
+ them in local time in the application:
121
+
122
+ Sequel.application_timezone = :local
123
+ Sequel.database_timezone = :utc
124
+
125
+ If you want to set all three timezones to the same value:
126
+
127
+ Sequel.default_timezone = :utc
128
+
129
+ There are three conversion methods that are called:
130
+
131
+ * Sequel.database_to_application_timestamp - Called on time objects
132
+ coming out of the database. If the object coming out of the
133
+ database (usually a string) does not have an offset, assume it is
134
+ already in the database_timezone. Return a Time/DateTime object
135
+ (depending on Sequel.datetime_class), in the application_timzone.
136
+
137
+ * Sequel.application_to_database_timestamp - Used when literalizing
138
+ Time/DateTime objects into an SQL string. Converts the object to
139
+ the database_timezone before literalizing them.
140
+
141
+ * Sequel.typecast_to_application_timestamp - Called when
142
+ typecasting objects for model datetime columns. If the object
143
+ being typecasted does not already have an offset, assume it is
144
+ already in the typecast_timezone. Return a Time/DateTime object
145
+ (depending on Sequel.datetime_class), in the
146
+ application_timezone.
147
+
148
+ Sequel does not yet support named timezones or per thread
149
+ modification of the timezone (for showing all timestamps in the
150
+ current user's timezone). Extensions to support both features are
151
+ planned for a future version.
152
+
153
+ * Dataset#truncate was added for truncating tables. Truncate allows
154
+ for fast removal of all rows in a table.
155
+
156
+ * Sequel now supports typecasting a hash to date, time, and datetime
157
+ types. This allows easy usage of Sequel with forms that split
158
+ the entry of these database types into separate from fields.
159
+ With this code, you can just have field names like:
160
+
161
+ date[year]
162
+ date[month]
163
+ date[day]
164
+
165
+ Rack will parse that into:
166
+
167
+ {'date'=>{'year'=>?, 'month'=>?, 'day'=>?}}
168
+
169
+ So then you can do:
170
+
171
+ obj.date = params['date']
172
+ # or
173
+ obj.set(params)
174
+
175
+ * validates_unique now takes a block that can be used to scope the
176
+ uniqueness constraint. This allows you to easily set up uniqueness
177
+ validations that are only necessary in a given scope. For example,
178
+ a validation on username, but only for active users (as inactive
179
+ users are soft deleted but remain in the table). You just pass a
180
+ block to validates_unique:
181
+
182
+ validates_unique(:name){|ds| ds.filter(:active)}
183
+
184
+ * The serialization plugin now supports json.
185
+
186
+ * Sequel now supports generic concepts of
187
+ CURRENT_{DATE,TIME,TIMESTAMP}. Most databases support these SQL
188
+ concepts, but not all, and some implementations act differently.
189
+
190
+ The Sequel::SQL::Constants module holds the three constants,
191
+ which are instances of SQL::Constant, an SQL::GenericExpression
192
+ subclass. This module is included in Sequel, so you can reference
193
+ the constants more easily (e.g. Sequel::CURRENT_TIMESTAMP).
194
+ It's separated out into a separate module so that you can just
195
+ include that module in the top level scope, allowing you to
196
+ reference the constants directly (e.g. CURRENT_TIMESTAMP).
197
+
198
+ DB[:events].filter{date < ::Sequel::CURRENT_DATE}
199
+ # or:
200
+ include Sequel::SQL::Constants
201
+ DB[:events].filter{date < ::CURRENT_DATE}
202
+
203
+ * Database#run was added for executing arbitrary SQL on a database.
204
+ It's an alias for Database#<<, but it allows for a nicer API inside
205
+ migrations, since you can now do:
206
+
207
+ run 'SQL'
208
+
209
+ instead of:
210
+
211
+ self << 'SQL'
212
+
213
+ You can also provide a :server option to run the SQL on the
214
+ given server/shard:
215
+
216
+ run 'SQL', :server=>:shard1
217
+
218
+ * Sequel::Model() can now take a database argument in addition to
219
+ a symbol or dataset argument. If a database is given, it'll create
220
+ an anonymous subclass attached to the given database. Other changes
221
+ were made to allow the following code to work:
222
+
223
+ class Item < Sequel::Model(DB2)
224
+ end
225
+
226
+ That will work correctly assuming a table named items in DB2.
227
+
228
+ * Dataset#ungrouped was added for removing a grouping from an
229
+ existing dataset. Also, Dataset#group when called with no arguments
230
+ or with a nil argument also removes any existing grouping instead
231
+ of resulting in invalid SQL.
232
+
233
+ * Model#modified? was added, letting you know if the model has been
234
+ modified. If the model hasn't been modified, calling
235
+ Model#save_changes will do nothing.
236
+
237
+ * SQL::OrderedExpression now supports #asc, #desc, and #invert.
238
+
239
+ Other Improvements
240
+ ------------------
241
+
242
+ * The serialization and lazy_attribute plugins now add accessor
243
+ methods to a module included in the class, instead of to the
244
+ model class itself. This allows the methods to be overridden
245
+ in the class and work well with super, as well for the plugins
246
+ to work together on the same column. Make sure the
247
+ lazy_attributes accessor is setup before the serialization
248
+ accessor if you want to have a lazy serialized column.
249
+
250
+ * Calling the add_* method for many_to_many association now saves the
251
+ record if the record is new. This makes it operate more similarly
252
+ to one_to_many associations. Previously, it raised an Error.
253
+
254
+ * Dataset#import now works correctly when called with a dataset.
255
+ Previously, it generated incorrect SQL.
256
+
257
+ * The JDBC adapter now converts byte arrays to/from SQL::Blob.
258
+
259
+ * The JDBC adapter now attempts to bind unknown types using
260
+ setObject instead of raising, so it can work with native Java
261
+ objects. It also binds boolean parameters correctly.
262
+
263
+ * Using multiple emulated ALTER TABLE statements (such as
264
+ drop_column) in a single alter_table block now works correctly
265
+ on SQLite.
266
+
267
+ * Database#indexes now works on JDBC for tables in a non-default
268
+ schema. It also now properly detects unique indexes on MSSQL.
269
+
270
+ * Database#schema on JDBC now accepts a :schema option. Also,
271
+ returned schema hashes now include a :column_size entry specifying
272
+ the maximum length/precision for the column, since the
273
+ :db_type entry doesn't have contain the information on JDBC.
274
+
275
+ * Datasets without tables now work correctly on Oracle, so things
276
+ like DB.get(...) now work.
277
+
278
+ * A descriptive error message is given if you attempt to use
279
+ Sequel with the mysql.rb driver (which Sequel doesn't support).
280
+
281
+ * The postgres adapter now works correctly with a modified
282
+ postgres-pr that raises PGErrors instead of RuntimeErrors
283
+ (e.g. http://github.com/jeremyevans/postgres-pr).
284
+
285
+ * You now get a Sequel::InvalidOperation instead of a NoMethodError
286
+ if you attempt to update a dataset without a table.
287
+
288
+ * The inflection support has been modified to reduce code
289
+ duplication.
290
+
291
+ Backwards Compatibility
292
+ -----------------------
293
+
294
+ * Sequel now includes fractional seconds in timestamps for all
295
+ adapters except MySQL. It's possible that this may break
296
+ timestamp columns for databases that are not regularly tested.
297
+
298
+ * Sequel now includes timezone values in timestamps on Microsoft
299
+ SQL Server, Oracle, PostgreSQL and SQLite. The modification for
300
+ SQLite is probably the biggest cause for concern, since SQLite
301
+ stores times as text. If you have an SQLite database that uses
302
+ timestamps and is accessed by something other than Sequel, you
303
+ should make sure that it works with the timestamp format that
304
+ Sequel now uses.
305
+
306
+ * The default timestamp format used by Sequel now uses a space
307
+ instead of 'T' between the date and time parts, which could
308
+ possibly affect some databases that are not regularly tested.
309
+
310
+ * Attempting to insert into a grouped dataset or a dataset that
311
+ selects from multiple tables will now raise an Error. Previously,
312
+ it would ignore any GROUP or JOIN settings and generate bad SQL if
313
+ there were multiple FROM tables.
314
+
315
+ * Database#<< now always returns nil. Before, the return value was
316
+ adapter dependent.
317
+
318
+ * ODBC::Time and ODBC::DateTime values are now converted to the
319
+ Sequel.datetime_class. Before, ODBC::Time used Time and
320
+ ODBC::DateTime used DateTime regardless of the
321
+ Sequel.datetime_class setting.
322
+
323
+ * The default inflections were modified, fixing some obvious errors
324
+ and possibly changing some existing inflections. Further changes
325
+ to the default inflections are unlikely.