sequel 3.47.0 → 3.48.0

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 (243) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +230 -0
  3. data/README.rdoc +31 -40
  4. data/Rakefile +1 -14
  5. data/doc/active_record.rdoc +29 -29
  6. data/doc/association_basics.rdoc +4 -13
  7. data/doc/cheat_sheet.rdoc +8 -6
  8. data/doc/code_order.rdoc +89 -0
  9. data/doc/core_extensions.rdoc +3 -3
  10. data/doc/dataset_basics.rdoc +7 -8
  11. data/doc/dataset_filtering.rdoc +7 -2
  12. data/doc/mass_assignment.rdoc +2 -3
  13. data/doc/migration.rdoc +8 -8
  14. data/doc/model_hooks.rdoc +11 -7
  15. data/doc/object_model.rdoc +2 -2
  16. data/doc/opening_databases.rdoc +5 -14
  17. data/doc/prepared_statements.rdoc +5 -9
  18. data/doc/querying.rdoc +23 -28
  19. data/doc/reflection.rdoc +11 -0
  20. data/doc/release_notes/3.48.0.txt +477 -0
  21. data/doc/schema_modification.rdoc +12 -5
  22. data/doc/security.rdoc +2 -2
  23. data/doc/sharding.rdoc +1 -2
  24. data/doc/sql.rdoc +10 -13
  25. data/doc/testing.rdoc +8 -4
  26. data/doc/transactions.rdoc +2 -2
  27. data/doc/validations.rdoc +40 -17
  28. data/doc/virtual_rows.rdoc +2 -2
  29. data/lib/sequel/adapters/ado.rb +25 -20
  30. data/lib/sequel/adapters/ado/access.rb +1 -0
  31. data/lib/sequel/adapters/ado/mssql.rb +1 -0
  32. data/lib/sequel/adapters/db2.rb +9 -7
  33. data/lib/sequel/adapters/dbi.rb +16 -16
  34. data/lib/sequel/adapters/do.rb +17 -18
  35. data/lib/sequel/adapters/do/mysql.rb +1 -0
  36. data/lib/sequel/adapters/do/postgres.rb +2 -0
  37. data/lib/sequel/adapters/do/sqlite.rb +1 -0
  38. data/lib/sequel/adapters/firebird.rb +5 -7
  39. data/lib/sequel/adapters/ibmdb.rb +23 -20
  40. data/lib/sequel/adapters/informix.rb +8 -2
  41. data/lib/sequel/adapters/jdbc.rb +39 -35
  42. data/lib/sequel/adapters/jdbc/as400.rb +1 -0
  43. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -0
  44. data/lib/sequel/adapters/jdbc/db2.rb +1 -0
  45. data/lib/sequel/adapters/jdbc/derby.rb +1 -0
  46. data/lib/sequel/adapters/jdbc/firebird.rb +1 -0
  47. data/lib/sequel/adapters/jdbc/h2.rb +1 -0
  48. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -0
  49. data/lib/sequel/adapters/jdbc/informix.rb +1 -0
  50. data/lib/sequel/adapters/jdbc/jtds.rb +1 -0
  51. data/lib/sequel/adapters/jdbc/mssql.rb +1 -0
  52. data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
  53. data/lib/sequel/adapters/jdbc/oracle.rb +1 -0
  54. data/lib/sequel/adapters/jdbc/postgresql.rb +2 -0
  55. data/lib/sequel/adapters/jdbc/progress.rb +1 -0
  56. data/lib/sequel/adapters/jdbc/sqlite.rb +1 -0
  57. data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -0
  58. data/lib/sequel/adapters/mock.rb +30 -31
  59. data/lib/sequel/adapters/mysql.rb +6 -7
  60. data/lib/sequel/adapters/mysql2.rb +5 -6
  61. data/lib/sequel/adapters/odbc.rb +22 -20
  62. data/lib/sequel/adapters/odbc/mssql.rb +1 -0
  63. data/lib/sequel/adapters/openbase.rb +4 -1
  64. data/lib/sequel/adapters/oracle.rb +10 -8
  65. data/lib/sequel/adapters/postgres.rb +12 -10
  66. data/lib/sequel/adapters/shared/access.rb +6 -0
  67. data/lib/sequel/adapters/shared/cubrid.rb +2 -0
  68. data/lib/sequel/adapters/shared/db2.rb +2 -0
  69. data/lib/sequel/adapters/shared/firebird.rb +2 -0
  70. data/lib/sequel/adapters/shared/informix.rb +2 -0
  71. data/lib/sequel/adapters/shared/mssql.rb +14 -8
  72. data/lib/sequel/adapters/shared/mysql.rb +6 -0
  73. data/lib/sequel/adapters/shared/oracle.rb +2 -0
  74. data/lib/sequel/adapters/shared/postgres.rb +14 -4
  75. data/lib/sequel/adapters/shared/progress.rb +1 -0
  76. data/lib/sequel/adapters/shared/sqlite.rb +4 -3
  77. data/lib/sequel/adapters/sqlite.rb +6 -7
  78. data/lib/sequel/adapters/swift.rb +20 -21
  79. data/lib/sequel/adapters/swift/mysql.rb +1 -0
  80. data/lib/sequel/adapters/swift/postgres.rb +2 -0
  81. data/lib/sequel/adapters/swift/sqlite.rb +1 -0
  82. data/lib/sequel/adapters/tinytds.rb +5 -6
  83. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +68 -0
  84. data/lib/sequel/connection_pool.rb +1 -1
  85. data/lib/sequel/core.rb +57 -50
  86. data/lib/sequel/database/connecting.rb +9 -10
  87. data/lib/sequel/database/dataset.rb +11 -6
  88. data/lib/sequel/database/dataset_defaults.rb +61 -69
  89. data/lib/sequel/database/features.rb +21 -0
  90. data/lib/sequel/database/misc.rb +23 -3
  91. data/lib/sequel/database/query.rb +13 -7
  92. data/lib/sequel/database/schema_methods.rb +6 -6
  93. data/lib/sequel/database/transactions.rb +1 -0
  94. data/lib/sequel/dataset/actions.rb +51 -38
  95. data/lib/sequel/dataset/features.rb +1 -0
  96. data/lib/sequel/dataset/graph.rb +9 -33
  97. data/lib/sequel/dataset/misc.rb +30 -5
  98. data/lib/sequel/dataset/mutation.rb +2 -3
  99. data/lib/sequel/dataset/prepared_statements.rb +1 -1
  100. data/lib/sequel/dataset/query.rb +91 -27
  101. data/lib/sequel/dataset/sql.rb +40 -6
  102. data/lib/sequel/deprecated.rb +74 -0
  103. data/lib/sequel/deprecated_core_extensions.rb +135 -0
  104. data/lib/sequel/extensions/columns_introspection.rb +1 -5
  105. data/lib/sequel/extensions/core_extensions.rb +10 -3
  106. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  107. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +33 -0
  108. data/lib/sequel/extensions/filter_having.rb +58 -0
  109. data/lib/sequel/extensions/graph_each.rb +63 -0
  110. data/lib/sequel/extensions/hash_aliases.rb +44 -0
  111. data/lib/sequel/extensions/looser_typecasting.rb +14 -3
  112. data/lib/sequel/extensions/migration.rb +2 -3
  113. data/lib/sequel/extensions/named_timezones.rb +14 -1
  114. data/lib/sequel/extensions/null_dataset.rb +7 -1
  115. data/lib/sequel/extensions/pagination.rb +15 -5
  116. data/lib/sequel/extensions/pg_auto_parameterize.rb +1 -0
  117. data/lib/sequel/extensions/pg_hstore_ops.rb +48 -14
  118. data/lib/sequel/extensions/pg_json.rb +7 -7
  119. data/lib/sequel/extensions/pg_range_ops.rb +8 -2
  120. data/lib/sequel/extensions/pg_statement_cache.rb +1 -0
  121. data/lib/sequel/extensions/pretty_table.rb +13 -4
  122. data/lib/sequel/extensions/query.rb +21 -4
  123. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +22 -0
  124. data/lib/sequel/extensions/schema_caching.rb +10 -7
  125. data/lib/sequel/extensions/schema_dumper.rb +35 -48
  126. data/lib/sequel/extensions/select_remove.rb +13 -4
  127. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +117 -0
  128. data/lib/sequel/extensions/set_overrides.rb +43 -0
  129. data/lib/sequel/extensions/to_dot.rb +6 -0
  130. data/lib/sequel/model.rb +12 -6
  131. data/lib/sequel/model/associations.rb +80 -38
  132. data/lib/sequel/model/base.rb +137 -52
  133. data/lib/sequel/model/errors.rb +7 -2
  134. data/lib/sequel/plugins/active_model.rb +13 -0
  135. data/lib/sequel/plugins/after_initialize.rb +43 -0
  136. data/lib/sequel/plugins/association_proxies.rb +63 -7
  137. data/lib/sequel/plugins/auto_validations.rb +56 -16
  138. data/lib/sequel/plugins/blacklist_security.rb +63 -0
  139. data/lib/sequel/plugins/class_table_inheritance.rb +9 -0
  140. data/lib/sequel/plugins/constraint_validations.rb +50 -8
  141. data/lib/sequel/plugins/dataset_associations.rb +2 -0
  142. data/lib/sequel/plugins/hook_class_methods.rb +7 -1
  143. data/lib/sequel/plugins/identity_map.rb +4 -0
  144. data/lib/sequel/plugins/json_serializer.rb +32 -13
  145. data/lib/sequel/plugins/optimistic_locking.rb +1 -1
  146. data/lib/sequel/plugins/rcte_tree.rb +4 -4
  147. data/lib/sequel/plugins/scissors.rb +33 -0
  148. data/lib/sequel/plugins/serialization.rb +1 -1
  149. data/lib/sequel/plugins/single_table_inheritance.rb +6 -0
  150. data/lib/sequel/plugins/tree.rb +5 -1
  151. data/lib/sequel/plugins/validation_class_methods.rb +2 -1
  152. data/lib/sequel/plugins/validation_helpers.rb +15 -11
  153. data/lib/sequel/plugins/xml_serializer.rb +12 -3
  154. data/lib/sequel/sql.rb +12 -2
  155. data/lib/sequel/timezones.rb +1 -1
  156. data/lib/sequel/version.rb +1 -1
  157. data/lib/sequel_core.rb +1 -0
  158. data/lib/sequel_model.rb +1 -0
  159. data/spec/adapters/mssql_spec.rb +24 -57
  160. data/spec/adapters/postgres_spec.rb +27 -55
  161. data/spec/adapters/spec_helper.rb +1 -1
  162. data/spec/adapters/sqlite_spec.rb +1 -1
  163. data/spec/bin_spec.rb +251 -0
  164. data/spec/core/database_spec.rb +46 -32
  165. data/spec/core/dataset_spec.rb +233 -181
  166. data/spec/core/deprecated_spec.rb +78 -0
  167. data/spec/core/expression_filters_spec.rb +3 -4
  168. data/spec/core/mock_adapter_spec.rb +9 -9
  169. data/spec/core/object_graph_spec.rb +9 -19
  170. data/spec/core/schema_spec.rb +3 -1
  171. data/spec/core/spec_helper.rb +19 -0
  172. data/spec/core_extensions_spec.rb +80 -30
  173. data/spec/extensions/after_initialize_spec.rb +24 -0
  174. data/spec/extensions/association_proxies_spec.rb +37 -1
  175. data/spec/extensions/auto_validations_spec.rb +20 -4
  176. data/spec/extensions/blacklist_security_spec.rb +87 -0
  177. data/spec/extensions/boolean_readers_spec.rb +2 -1
  178. data/spec/extensions/class_table_inheritance_spec.rb +7 -0
  179. data/spec/extensions/columns_introspection_spec.rb +3 -3
  180. data/spec/extensions/constraint_validations_plugin_spec.rb +83 -5
  181. data/spec/extensions/core_refinements_spec.rb +7 -7
  182. data/spec/extensions/dataset_associations_spec.rb +2 -2
  183. data/spec/extensions/date_arithmetic_spec.rb +1 -1
  184. data/spec/extensions/defaults_setter_spec.rb +2 -1
  185. data/spec/extensions/empty_array_ignore_nulls_spec.rb +24 -0
  186. data/spec/extensions/filter_having_spec.rb +40 -0
  187. data/spec/extensions/graph_each_spec.rb +109 -0
  188. data/spec/extensions/hash_aliases_spec.rb +16 -0
  189. data/spec/extensions/hook_class_methods_spec.rb +2 -2
  190. data/spec/extensions/identity_map_spec.rb +3 -3
  191. data/spec/extensions/json_serializer_spec.rb +19 -19
  192. data/spec/extensions/lazy_attributes_spec.rb +1 -0
  193. data/spec/extensions/list_spec.rb +13 -13
  194. data/spec/extensions/looser_typecasting_spec.rb +10 -3
  195. data/spec/extensions/many_through_many_spec.rb +1 -1
  196. data/spec/extensions/migration_spec.rb +7 -7
  197. data/spec/extensions/named_timezones_spec.rb +6 -0
  198. data/spec/extensions/nested_attributes_spec.rb +2 -2
  199. data/spec/extensions/null_dataset_spec.rb +1 -1
  200. data/spec/extensions/pagination_spec.rb +2 -2
  201. data/spec/extensions/pg_hstore_ops_spec.rb +75 -0
  202. data/spec/extensions/pg_range_ops_spec.rb +4 -2
  203. data/spec/extensions/pg_row_plugin_spec.rb +1 -1
  204. data/spec/extensions/pretty_table_spec.rb +1 -1
  205. data/spec/extensions/query_literals_spec.rb +1 -1
  206. data/spec/extensions/query_spec.rb +3 -3
  207. data/spec/extensions/schema_caching_spec.rb +3 -3
  208. data/spec/extensions/schema_dumper_spec.rb +27 -2
  209. data/spec/extensions/schema_spec.rb +2 -2
  210. data/spec/extensions/scissors_spec.rb +26 -0
  211. data/spec/extensions/select_remove_spec.rb +1 -1
  212. data/spec/extensions/sequel_3_dataset_methods_spec.rb +102 -0
  213. data/spec/extensions/set_overrides_spec.rb +45 -0
  214. data/spec/extensions/single_table_inheritance_spec.rb +10 -0
  215. data/spec/extensions/spec_helper.rb +24 -1
  216. data/spec/extensions/static_cache_spec.rb +1 -1
  217. data/spec/extensions/string_stripper_spec.rb +2 -1
  218. data/spec/extensions/to_dot_spec.rb +1 -1
  219. data/spec/extensions/typecast_on_load_spec.rb +3 -2
  220. data/spec/extensions/update_primary_key_spec.rb +2 -2
  221. data/spec/extensions/validation_class_methods_spec.rb +19 -19
  222. data/spec/extensions/validation_helpers_spec.rb +30 -21
  223. data/spec/extensions/xml_serializer_spec.rb +5 -5
  224. data/spec/integration/associations_test.rb +10 -30
  225. data/spec/integration/dataset_test.rb +20 -24
  226. data/spec/integration/eager_loader_test.rb +5 -5
  227. data/spec/integration/model_test.rb +3 -3
  228. data/spec/integration/plugin_test.rb +7 -39
  229. data/spec/integration/schema_test.rb +4 -38
  230. data/spec/integration/spec_helper.rb +2 -1
  231. data/spec/model/association_reflection_spec.rb +70 -5
  232. data/spec/model/associations_spec.rb +11 -11
  233. data/spec/model/base_spec.rb +25 -8
  234. data/spec/model/class_dataset_methods_spec.rb +143 -0
  235. data/spec/model/dataset_methods_spec.rb +1 -1
  236. data/spec/model/eager_loading_spec.rb +25 -25
  237. data/spec/model/hooks_spec.rb +1 -1
  238. data/spec/model/model_spec.rb +22 -7
  239. data/spec/model/plugins_spec.rb +1 -6
  240. data/spec/model/record_spec.rb +37 -29
  241. data/spec/model/spec_helper.rb +23 -1
  242. data/spec/model/validations_spec.rb +15 -17
  243. metadata +32 -3
@@ -87,16 +87,13 @@ to create prepared statements dynamically at runtime.
87
87
  === PostgreSQL
88
88
 
89
89
  If you are using the ruby-postgres or postgres-pr driver, PostgreSQL uses the
90
- default emulated support. If you are using ruby-pg, there is native support,
91
- but it may require type specifiers on some old versions (generally not anymore).
92
- You can add a __* suffix to the placeholder symbol to specify a type, which
93
- casts to that type in the SQL (e.g. :$name__text, which will be compiled to
94
- "$1::text" in the SQL). Prepared statements are always server side.
90
+ default emulated support. If you are using ruby-pg, there is native support
91
+ for both prepared statements and bound variables. Prepared statements are
92
+ always server side.
95
93
 
96
94
  === SQLite
97
95
 
98
- SQLite supports both prepared statements and bound variables. Prepared
99
- statements are cached per connection.
96
+ SQLite supports both prepared statements and bound variables.
100
97
 
101
98
  === MySQL/Mysql2
102
99
 
@@ -119,8 +116,7 @@ Microsoft SQL Server doesn't support true prepared statements.
119
116
 
120
117
  === IBM_DB
121
118
 
122
- DB2 supports both prepared statements and bound variables. Prepared
123
- statement objects are cached per connection.
119
+ DB2 supports both prepared statements and bound variables.
124
120
 
125
121
  === Oracle
126
122
 
@@ -42,7 +42,10 @@ by its primary key value:
42
42
  # SELECT * FROM artists WHERE id = 1
43
43
  => #<Artist @values={:name=>"YJM", :id=>1}>
44
44
 
45
- If there is no record with the given primary key, nil will be returned.
45
+ If there is no record with the given primary key, nil will be returned. If you want
46
+ to raise an exception if no record is found, you can use <tt>Sequel::Model.with_pk!</tt>:
47
+
48
+ artist = Artist.with_pk!(1)
46
49
 
47
50
  ==== Using +first+
48
51
 
@@ -63,6 +66,9 @@ Any options you pass to +first+ will be used as a filter:
63
66
  # SELECT * FROM artists WHERE (name LIKE 'Y%') LIMIT 1
64
67
  => #<Artist @values={:name=>"YJM", :id=>1}>
65
68
 
69
+ If there is no matching row, +first+ will return nil. If you want to
70
+ raise an exception instead, use <tt>first!</tt>.
71
+
66
72
  <tt>Sequel::Dataset#[]</tt> is basically an alias for +first+, except it
67
73
  requires an argument:
68
74
 
@@ -77,16 +83,17 @@ Dataset#[] does not (unless it is a model dataset).
77
83
 
78
84
  If you want the last record in the dataset,
79
85
  <tt>Sequel::Dataset#last</tt> is an obvious method to use. Note
80
- that last requires that the dataset be ordered. Without an order, any
81
- object can be considered the first as well as the last.
86
+ that last requires that the dataset be ordered, unless the
87
+ dataset is a model dataset. For a model dataset, +last+ will do a
88
+ reverse order by the primary key field:
82
89
 
83
- artist = Artist.order(:name).last
84
- # SELECT * FROM artists ORDER BY name DESC LIMIT 1
90
+ artist = Artist.last
91
+ # SELECT * FROM artists ORDER BY id DESC LIMIT 1
85
92
  => #<Artist @values={:name=>"YJM", :id=>1}>
86
93
 
87
- Note that all +last+ does is reverse the order of the dataset and then
94
+ Note that what +last+ does is reverse the order of the dataset and then
88
95
  call +first+. This is why +last+ raises a Sequel::Error if there is no
89
- order on the dataset, because otherwise it would provide the same record
96
+ order on a plain dataset, because otherwise it would provide the same record
90
97
  as +first+, and most users would find that confusing.
91
98
 
92
99
  Note that +last+ is not necessarily going to give you the last record
@@ -302,8 +309,7 @@ any part of the query at any time.
302
309
 
303
310
  Filtering is probably the most common dataset modifying action done in Sequel.
304
311
  Both the +where+ and +filter+ methods filter the dataset by modifying the
305
- dataset's WHERE clause. While not quite aliases of each other, they operate
306
- the same in most cases. Both accept a wide variety of input formats, discussed
312
+ dataset's WHERE clause. Both accept a wide variety of input formats, discussed
307
313
  below.
308
314
 
309
315
  === Hashes
@@ -454,7 +460,7 @@ sure of what you are doing.
454
460
 
455
461
  Artist.where("id = #{params[:id]}") # Don't do this!
456
462
  Artist.where("id = ?", params[:id]) # Do this instead
457
- Artist.where(:id=>params[:id]) # Even better
463
+ Artist.where(:id=>params[:id].to_i) # Even better
458
464
 
459
465
  === Inverting
460
466
 
@@ -650,7 +656,7 @@ A common use of grouping is to count based on the number of grouped rows,
650
656
  and Sequel provides a +group_and_count+ method to make this easier:
651
657
 
652
658
  Album.group_and_count(:artist_id)
653
- # SELECT artist_id, COUNT(*) AS count FROM albums GROUP BY artist_id
659
+ # SELECT artist_id, count(*) AS count FROM albums GROUP BY artist_id
654
660
 
655
661
  This will return the number of albums for each artist_id.
656
662
 
@@ -673,26 +679,14 @@ before. One possible use is if you only wanted to return artists
673
679
  who had at least 10 albums:
674
680
 
675
681
  Album.group_and_count(:artist_id).having{count >= 10}
676
- # SELECT artist_id, COUNT(*) AS count FROM albums
682
+ # SELECT artist_id, count(*) AS count FROM albums
677
683
  # GROUP BY artist_id HAVING count >= 10
678
684
 
679
- If you have an existing HAVING clause on your dataset, then +filter+
680
- will add to the HAVING clause instead of the WHERE clause:
681
-
682
- Album.group_and_count(:artist_id).
683
- having{count >= 10}.filter{count < 15}
684
- # SELECT artist_id, COUNT(*) AS count FROM albums
685
- # GROUP BY artist_id HAVING count >= 10 AND count < 15
686
-
687
- This can be confusing, so it is recommended that you always use
688
- either +having+ or +where+ instead of +filter+, indicating which
689
- clause that would want affected.
690
-
691
685
  Both the WHERE clause and the HAVING clause are removed by +unfiltered+:
692
686
 
693
687
  Album.group_and_count(:artist_id).having{count >= 10}.
694
688
  where(:name.like('A%')).unfiltered
695
- # SELECT artist_id, COUNT(*) AS count FROM albums GROUP BY artist_id
689
+ # SELECT artist_id, count(*) AS count FROM albums GROUP BY artist_id
696
690
 
697
691
  == Joins
698
692
 
@@ -806,7 +800,8 @@ a JOIN using case insensitive string comparison:
806
800
  # SELECT * FROM albums INNER JOIN artists
807
801
  # ON (lower(artists.name) = lower(albums.artist_name))
808
802
 
809
- Note how the arguments to lower were qualified correctly in both cases.
803
+ Note how the arguments to lower were qualified correctly in both cases. Starting in Sequel 4,
804
+ the <tt>:qualify=>:deep</tt> option is going to become the default.
810
805
 
811
806
  ==== USING Joins
812
807
 
@@ -922,7 +917,7 @@ it and when the transaction ends.
922
917
 
923
918
  === Optimistic Locking
924
919
 
925
- One of Sequel's built-in model plugins is an optimistic locking plugin, which provides
920
+ One of the model plugins that ships with Sequel is an optimistic locking plugin, which provides
926
921
  a database independent way to detect and raise an error if two different connections
927
922
  modify the same row. It's useful for things like web forms where you cannot keep a
928
923
  transaction open while the user is looking at the form, because of the web's
@@ -994,7 +989,7 @@ for each of these aggregate functions.
994
989
  +count+ just returns the number of records in the dataset.
995
990
 
996
991
  Album.count
997
- # SELECT COUNT(*) AS count FROM albums LIMIT 1
992
+ # SELECT count(*) AS count FROM albums LIMIT 1
998
993
  => 2
999
994
 
1000
995
  The other methods take a column argument and call the aggregate function with
@@ -108,3 +108,14 @@ You can get an array of all association reflections via Model.all_association_re
108
108
  Finally, you can get a hash of association reflections via Model.association_reflections:
109
109
 
110
110
  Model.association_reflections # {:association1=>{:name=>:association1, :type=>:many_to_one, :model=>Model, ...}, ...}
111
+
112
+ == Validations Defined
113
+
114
+ When using the validation_class_methods plugin, you can use the validation_reflections class method to get a hash with validation reflection information. This returns a hash keyed on the column name symbol:
115
+
116
+ Model.validation_reflections[:column] # => [[:presence, {}], [:length, {:maximum=>255, :message=>'is just too long'}]]
117
+
118
+ Similarly, when using the constraint_validations plugin, you can use the constraint_validation_reflections class method:
119
+
120
+ Model.constraint_validation_reflections[:column] # => [[:presence, {}], [:max_length, {:argument=>255, :message=>'is just too long'}]]
121
+
@@ -0,0 +1,477 @@
1
+ = Deprecation Warnings
2
+
3
+ The main change in Sequel 3.48.0 is the deprecation of Sequel
4
+ features that will be modified, moved, or removed in Sequel 4.
5
+ For the reasoning behind these changes, please review the
6
+ commits logs at
7
+ https://github.com/jeremyevans/sequel-4-plans/commits/master
8
+
9
+ == Deprecation Logging
10
+
11
+ If you use a deprecated method or feature, Sequel will by default
12
+ print a deprecation message and 10 lines of backtrace to stderr
13
+ to easily allow you to figure out which code needs to be
14
+ updated. You can change where the deprecation messages go and how
15
+ many lines of backtrace are given using the following:
16
+
17
+ # Log deprecation information to a file
18
+ Sequel::Deprecation.output = File.open('deprecated.txt', 'wb')
19
+
20
+ # Turn off all deprecation logging
21
+ Sequel::Deprecation.output = nil
22
+
23
+ # Use 5 lines of backtrace when logging deprecation messages
24
+ Sequel::Deprecation.backtrace_filter = 5
25
+
26
+ # Use all backtrace lines when logging deprecation messages
27
+ Sequel::Deprecation.backtrace_filter = true
28
+
29
+ # Don't include backtraces in the deprecation logging
30
+ Sequel::Deprecation.backtrace_filter = false
31
+
32
+ # Select which backtrace lines to output
33
+ Sequel::Deprecation.backtrace_filter = \
34
+ lambda{|line, line_no| line_no < 3 || line =~ /my_app/}
35
+
36
+ == Major Change
37
+
38
+ * The core extensions will no longer be loaded by default. You will
39
+ have to use `Sequel.extension :core_extensions` to load the core
40
+ extensions.
41
+
42
+ * The Symbol#[] and Symbol#{<,>,<=,>=} methods will no longer be
43
+ provided by the core extensions on ruby 1.8. You will have to
44
+ use `Sequel.extension :ruby18_symbol_extensions` to use them.
45
+
46
+ == Core Behavior Changes
47
+
48
+ * Dataset#filter becomes an alias for #where, and #exclude
49
+ becomes an alias for #exclude_where. You will have to
50
+ use `DB.extension :filter_having` to get the previous behavior.
51
+ Dataset#and and #or will also only affect the WHERE clause.
52
+
53
+ * Dataset#and, #or, and #invert will not raise errors for no existing
54
+ filter.
55
+
56
+ * Dataset#select_more becomes an alias for #select_append.
57
+
58
+ * Dataset#select and #from will not longer consider a hash argument as
59
+ an alias specification. You will have to use
60
+ `DB.extension :hash_aliases` to get the previous behavior.
61
+
62
+ * Database#dataset and Dataset.new will not take an options hash.
63
+
64
+ * Database#transaction :disconnect=>:retry option will be removed.
65
+
66
+ * Calling Dataset#add_graph_aliases before #graph or #set_graph_aliases
67
+ will raise an Error.
68
+
69
+ * Datasets will have a frozen options hash by default.
70
+
71
+ * Dataset#set_overrides and #set_defaults will move to the
72
+ set_overrides extension.
73
+
74
+ * Sequel.empty_array_handle_nulls will be removed. To get the
75
+ empty_array_handle_nulls = false behavior, you will have to
76
+ use `DB.extension :empty_array_ignore_nulls`.
77
+
78
+ * The second argument to Dataset #union, #intersect, and #except must
79
+ be an options hash if it is given.
80
+
81
+ * The fourth argument to Dataset #join_table must be an options
82
+ hash if it is given.
83
+
84
+ * Using a mismatched number of placeholders and arguments in a
85
+ placeholder literal string will raise an error.
86
+
87
+ * Dataset#graph_each will move to the graph_each extension.
88
+
89
+ * Database#default_schema will be removed.
90
+
91
+ * Dataset#[]= will be moved to the sequel_3_dataset_methods
92
+ extension.
93
+
94
+ * Dataset#insert_multiple will be moved to the
95
+ sequel_3_dataset_methods extension.
96
+
97
+ * Dataset#set will be moved to the sequel_3_dataset_methods
98
+ extension.
99
+
100
+ * Dataset#to_csv will be moved to the sequel_3_dataset_methods
101
+ extension.
102
+
103
+ * Dataset#db= and #opts= setters will be moved to the
104
+ sequel_3_dataset_methods extension.
105
+
106
+ * Dataset#qualify_to and #qualify_to_first_source will be moved to
107
+ the sequel_3_dataset_methods extension.
108
+
109
+ * Remove default methods that raise Sequel::NotImplemented:
110
+ Database#connect, #execute, #foreign_key_list, #indexes, #tables,
111
+ and #views, and Dataset#fetch_rows.
112
+
113
+ * Sequel::SQL::Expression#to_s will be removed.
114
+
115
+ * All Dataset methods in Dataset::PUBLIC_APPEND_METHODS except for
116
+ #literal, #quote_identifier, and #quote_schema_table will be
117
+ removed.
118
+
119
+ * All Dataset methods in Dataset::PRIVATE_APPEND_METHODS will
120
+ be removed.
121
+
122
+ * Sequel k_require, ts_require, tsk_require, and
123
+ check_requiring_thread will be removed.
124
+
125
+ * Dataset.def_append_methods will be removed.
126
+
127
+ * Dataset#table_ref_append will be removed.
128
+
129
+ * Sequel.virtual_row_instance_eval accessor will be removed.
130
+
131
+ * Database#reset_schema_utility_dataset will be removed.
132
+
133
+ == Adapter Behavior Changes
134
+
135
+ * The Database#do method will be removed from the ado, db2, dbi,
136
+ informix, odbc, openbase, and oracle adapters.
137
+
138
+ * The jdbc adapter will raise an error when parsing the schema
139
+ for a table if it detects results for the same table name in
140
+ multiple schemas.
141
+
142
+ * The Database#query method will be removed from the informix
143
+ adapter.
144
+
145
+ * Dataset#lock on PostgreSQL will check the given lock mode.
146
+
147
+ * Sequel will check the client_min_messages setting before
148
+ use on PostgreSQL.
149
+
150
+ * Prepared statement placeholders on PostgreSQL will no longer
151
+ support implicit casting via :$x__type.
152
+
153
+ == Extension Behavior Changes
154
+
155
+ * The following extensions will no longer make global changes to
156
+ the Database and Dataset classes: null_dataset, pagination,
157
+ pretty_table, query, schema_caching, schema_dumper,
158
+ select_remove, and to_dot. These will be changed to
159
+ Database/Dataset specific extensions.
160
+
161
+ * The pg_auto_parameterize and pg_statement_cache extensions will
162
+ be removed.
163
+
164
+ * Sequel::Dataset.introspect_all_columns will be removed from the
165
+ columns_introspection extension.
166
+
167
+ * PGRangeOp#starts_before and #ends_after will be removed from the
168
+ pg_range_ops extension.
169
+
170
+ == Model Behavior Changes
171
+
172
+ * Model#initialize will accept only one argument.
173
+
174
+ * The after_initialize hook will be moved to a plugin.
175
+
176
+ * Move blacklist-based security methods (#set_except, #update_except,
177
+ .set_restricted_columns) to a plugin.
178
+
179
+ * The :eager_loader and :eager_grapher association option procs will
180
+ always be passed a hash.
181
+
182
+ * Model string column setters will consider array and hash input to
183
+ be invalid.
184
+
185
+ * Remove save taking multiple arguments for the columns to save.
186
+ Add Model#save :columns option for saving specific columns.
187
+
188
+ * Don't automatically choose a reciprocal association with a condition
189
+ or block.
190
+
191
+ * Don't automatically set up reciprocal associations if multiple ones
192
+ match.
193
+
194
+ * Model::Errors#[] will no longer modify the receiver. If you want
195
+ autovivification, use the active_model plugin.
196
+
197
+ * Model.set_primary_key will not longer accept composite keys as
198
+ multiple arguments.
199
+
200
+ * The correlated_subquery eager limit strategy will be removed.
201
+
202
+ * The following Model class dataset methods will be removed: print,
203
+ each_page, paginate, set, add_graph_aliases, insert_multiple, query,
204
+ set_overrides, set_defaults, to_csv.
205
+
206
+ * The Model.{destroy,delete,update} class dataset methods will be
207
+ moved to the scissors plugin.
208
+
209
+ * Model#pk_or_nil will be removed.
210
+
211
+ * Model#set_values will no longer be called directly by any Sequel
212
+ code, and overriding it is deprecated. It will be removed in Sequel
213
+ 4.1.
214
+
215
+ * Model.cache_anonymous_models accessor will move to Sequel module.
216
+
217
+ * Model::InstanceMethods.class_attr_overridable and
218
+ .class_attr_reader will be removed.
219
+
220
+ * The :one_to_one option check for one_to_many associations will
221
+ be removed.
222
+
223
+ == Plugin Behavior Changes
224
+
225
+ * Public dataset methods will no longer have class methods
226
+ automatically added.
227
+
228
+ * The validates_not_string validation will be removed from the
229
+ validation_class_methods and validation_helpers plugin.
230
+
231
+ * In the json_serializer plugin, the to_json :root=>true option
232
+ means :root=>:collection instead of :root=>:both.
233
+
234
+ * In the json_serializer plugin, the to_json :naked option will
235
+ default to true, and there will not be way to add the JSON.create_id
236
+ automatically.
237
+
238
+ * In the json_serializer plugin, from_json will no longer automatically
239
+ delete the JSON.create_id key from the input hash.
240
+
241
+ * The #to_json and #to_xml :all_columns and :all_associations options
242
+ in the json_serializer and xml_serializer plugins will be removed.
243
+
244
+ * The Model.json_create method will be removed from the
245
+ json_serializer plugin.
246
+
247
+ * The validates_type validation will raise validation errors for nil
248
+ if :allow_nil=>true is not used.
249
+
250
+ * auto_validate_presence_columns will be removed from the
251
+ auto_validations plugin
252
+
253
+ * The identity_map plugin will be removed.
254
+
255
+ == Internal Changes
256
+
257
+ * The sequel_core.rb and sequel_model.rb files will be removed.
258
+
259
+ * Dataset#{quote_identifiers,identifier_output_method,
260
+ identifier_input_method} will assume Database implements the
261
+ methods.
262
+
263
+ = Forwards Compatibility
264
+
265
+ Not all changes planned in Sequel 4 have deprecation warnings.
266
+ The following changes will be made in Sequel 4 but do not have
267
+ deprecation warnings in 3.48.0:
268
+
269
+ * The threaded connection pools will default to
270
+ :connection_handling=>:queue. You can manually set
271
+ :connection_handling=>:stack to get the current behavior.
272
+
273
+ * Dataset#join_table will default to :qualify=>:deep. You can
274
+ manually set :qualify=>:symbol to get the current behavior. This
275
+ can be set at a global level by overriding
276
+ Dataset#default_join_table_qualification.
277
+
278
+ * Model.raise_on_typecast_failure will default to false. Set this to
279
+ true to get the current behavior of raising typecast errors in the
280
+ setter methods.
281
+
282
+ * Model#save will no longer call Model#_refresh or Model#set_values
283
+ internally after an insert. Manually refreshes will be treated
284
+ differently than after creation refreshes in Sequel 4.
285
+
286
+ * On SQLite, integer_booleans will be true by default. Set this to
287
+ false to get the current behavior of 't' for true and 'f' for false.
288
+
289
+ * On SQLite, use_timestamp_timezones will be false by default. Set
290
+ this to true to get the current behavior with timezone information
291
+ in timestamps.
292
+
293
+ * The default value for most option hash arguments will be an empty
294
+ frozen hash. If you are overriding methods and modifying option
295
+ hashes, fix your code.
296
+
297
+ * The defaults_setter plugin will work in a lazy manner instead of
298
+ an eager manner. If you must have the values hash contain defaults
299
+ for new objects (instead of just getting defaults from getter
300
+ methods), you'll need to fork the current plugin.
301
+
302
+ * Model#set_all will allow setting the primary key columns.
303
+
304
+ * The many_to_one_pk_lookup plugin will be integrated into the
305
+ default associations support.
306
+
307
+ * The association_autoreloading plugin will be integrated into the
308
+ default associations support.
309
+
310
+ * Plugins will extend the class with ClassMethods before including
311
+ InstanceMethods in the class.
312
+
313
+ * Dataset#get, #select_map, and #select_order_map will automatically
314
+ add aliases for unaliased expressions if given a single expression.
315
+
316
+ * Database#tables and #views on PostgreSQL will check against
317
+ the current schemas in the search path.
318
+
319
+ * Sequel::SQL::SQLArray alias for ValueList will be removed.
320
+
321
+ * Sequel::SQL::NoBooleanInputMethods will be removed.
322
+
323
+ * Sequel::NotImplemented will be removed.
324
+
325
+ * Sequel::Model::EMPTY_INSTANCE_VARIABLES will be removed.
326
+
327
+ * Sequel will no longer provide a default database for the adapter or
328
+ integration specs.
329
+
330
+ = New Features
331
+
332
+ * You can now choose which Errors class to use on a per model basis
333
+ by overriding Model#errors_class.
334
+
335
+ * The following Database methods have been added to check for support:
336
+ supports_index_parsing?, supports_foreign_key_parsing?,
337
+ support_table_listing?, supports_view_listing?.
338
+
339
+ * The pg_hstore_ops extension now integrates with the pg_array,
340
+ pg_hstore, and pg_array_ops extensions, allowing you to pass in
341
+ arrays and hashes to be treated as PGArrays and HStores, and
342
+ returning ArrayOps for PostgreSQL functions/operators that
343
+ return arrays.
344
+
345
+ * Sequel.object_to_json and Sequel.json_parser_error_class
346
+ have been added and all internal json usage uses them, so you
347
+ can now override these methods if you want to use an alternative
348
+ json library with Sequel.
349
+
350
+ * The association_proxies plugin now accepts a block allowing the
351
+ user control over which methods are proxied to the dataset or
352
+ the cached array of instances. You can base the decision on
353
+ where to send the method using a variety of factors including
354
+ the method name, the method arguments, the state of the current
355
+ instance, or the related association. Here's an example of a
356
+ simple case just depending on the name of the method;
357
+
358
+ Model.plugin :association_proxies do |opts|
359
+ [:find, :where, :create].include?(opts[:method])
360
+ end
361
+
362
+ If the block returns true, the method is sent to the dataset,
363
+ otherwise it is sent to the array of associated objects.
364
+
365
+ * The auto_validations plugin now accepts a :not_null=>:presence
366
+ option, for doing a presence validation instead of a not_null
367
+ validation. This is useful for databases with NOT NULL
368
+ constraints where you also want to disallow empty strings.
369
+
370
+ * The auto_validations plugin now validates against explicit nil
371
+ values in NOT NULL columns that have defaults.
372
+
373
+ * The constraint_validations plugin now reflects validations, using
374
+ Model.constraint_validation_reflections.
375
+
376
+ Model.constraint_validation_reflections[:column]
377
+ # => [[:presence, {}],
378
+ # [:max_length, {:argument=>255, :message=>'just too long'}]]
379
+
380
+ * The constraint_validations plugin can now be set to pass specific
381
+ validations options to the validation_helpers plugin. This can be
382
+ useful if using the auto_validations plugin with this plugin to
383
+ avoid duplicate error messages for nil values:
384
+
385
+ Model.plugin :constraint_validations,
386
+ :validates_options=>{:presence=>{:allow_nil=>true}}
387
+
388
+ * The named_timezones extension can now be loaded as a database
389
+ extension, which allows for automatic conversions of string
390
+ timezones:
391
+
392
+ DB.extension :named_timezones
393
+ DB.timezone = 'America/Los_Angeles'
394
+
395
+ * Offsets are now emulated by Microsoft Access using a combination
396
+ of reverse orders and total counts. This is slow, especially on
397
+ large datasets, but probably better than having no support at all.
398
+ It is also possible to use the same code to support Microsoft
399
+ SQL Server 2000, but as Sequel does not support that (minimum
400
+ supported version is 2005), you have to do it manually:
401
+
402
+ Sequel.require 'adapters/utils/emulate_offset_with_reverse_and_count'
403
+ DB.extend_datasets Sequel::EmulateOffsetWithReverseAndCount
404
+
405
+ = Other Improvements
406
+
407
+ * Dataset#clone is now faster.
408
+
409
+ * Database methods that create datasets (fetch, from, select, get)
410
+ are now faster.
411
+
412
+ * Model.with_pk and .with_pk! are now faster.
413
+
414
+ * Dataset#or now just clones if given an empty argument, similar
415
+ to Dataset#where.
416
+
417
+ * Sequel now correctly frees statements after using them in the
418
+ ibmdb adapter. Previously, they weren't freed until GC, which
419
+ could result in errors if all available handles are in use.
420
+
421
+ * Dataset creation is now faster on Microsoft SQL Server.
422
+
423
+ * The mediumint and mediumtext types are now recognized on MySQL.
424
+
425
+ * The ado adapter now handles disconnecting an already disconnected
426
+ connection.
427
+
428
+ * The auto_validations plugin now works on databases that don't
429
+ support index parsing. However, it will not set up automatic
430
+ uniqueness validations on such databases.
431
+
432
+ * The validation_helpers is more strict in some cases when checking
433
+ for nil values, using a specific nil check instead of general
434
+ falsely check.
435
+
436
+ * The table inheritance plugins now correctly handle usage of
437
+ set_dataset in a subclass.
438
+
439
+ * The bin/sequel command line tool now has specs.
440
+
441
+ = Backwards Compatibility
442
+
443
+ * Sequel now uses aliases for many internal Dataset#get calls, such
444
+ as those used by table_exists? and max.
445
+
446
+ * Sequel now no longer uses class variables internally. Instead,
447
+ instance variables of the Sequel::Database class are used.
448
+
449
+ * Sequel now sets up the identifier mangling methods on Database
450
+ initialization instead of on first use.
451
+
452
+ * The private Database#adapter_initialize method has been added for
453
+ per adapter configuration. All internal adapters have been switched
454
+ to use this method instead of overridding initialize, and all
455
+ external adapters should as well. This makes sure that Database
456
+ instances are not added to Sequel::DATABASES until they have been
457
+ completely initialized.
458
+
459
+ * Virtual row blocks no longer convert their return values to an array.
460
+ Among other things, this means that having a virtual row block return
461
+ a hash works as expected.
462
+
463
+ * The private Dataset#hash_key_symbol method now only takes a single
464
+ argument.
465
+
466
+ * Database#constraint_validations in the constraint_validations plugin
467
+ now returns raw hash rows, instead of arrays of validation method
468
+ call arguments.
469
+
470
+ * Dataset#count now uses a lowercase count function in the SQL.
471
+
472
+ * Passing a non-String or Hash as the first argument to an adapter
473
+ method (e.g. Sequel.postgres(1)) now raises an error. Before, this used
474
+ to work on some adapters that implicitly converted the database
475
+ name to a string.
476
+
477
+ * The stats and dcov rake tasks were removed.