sequel 3.47.0 → 3.48.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1080,11 +1080,11 @@ Can use an array of symbols for a composite key association.
1080
1080
  A proc that can be used to modify the dataset used in the add/remove/remove_all
1081
1081
  methods. It's separate from the association block, as that is called on a
1082
1082
  join of the join table and the associated table, whereas this option just
1083
- applies to the join table. It can be used to make sure additional columns are
1084
- used when inserting, or that filters are used when deleting.
1083
+ applies to the join table. It can be used to make sure that filters are used
1084
+ when deleting.
1085
1085
 
1086
1086
  Artist.many_to_many :lead_guitar_albums, :join_table_block=>proc do |ds|
1087
- ds.where(:instrument_id=>5).set_overrides(:instrument_id=>5)
1087
+ ds.where(:instrument_id=>5)
1088
1088
  end
1089
1089
 
1090
1090
  === Callback Options
@@ -1575,7 +1575,7 @@ you also wanted to handle the Artist#remove_all_albums method:
1575
1575
 
1576
1576
  The symbol name of the reciprocal association, if it exists. By default,
1577
1577
  Sequel will try to determine it by looking at the associated model's
1578
- assocations for a association that matches the current association's key(s).
1578
+ associations for a association that matches the current association's key(s).
1579
1579
  Set to nil to not use a reciprocal.
1580
1580
 
1581
1581
  Reciprocals are used in Sequel to modify the matching cached associations
@@ -1704,15 +1704,6 @@ strategies are:
1704
1704
  :window_function :: Uses window functions if the database supports it.
1705
1705
  This is used by default on databases that support window
1706
1706
  functions.
1707
- :correlated_subquery :: Uses a correlated subquery to get the information.
1708
- This is never used by default as if you aren't careful,
1709
- it can result in pathologically long running times.
1710
- This will not work correctly for associations where
1711
- the associated table has a composite primary key if
1712
- the database doesn't support using IN
1713
- with multiple columns. This will also not work on MySQL
1714
- because MySQL has problems using IN with a correlated
1715
- subquery that contains a limit.
1716
1707
  :ruby :: Uses ruby array slicing to emulate database limiting (*_many
1717
1708
  associations only). This is the default if the database doesn't
1718
1709
  support window functions.
@@ -2,7 +2,6 @@
2
2
 
3
3
  == Open a database
4
4
 
5
- require 'rubygems'
6
5
  require 'sequel'
7
6
 
8
7
  DB = Sequel.sqlite('my_blog.db')
@@ -62,7 +61,7 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
62
61
  dataset.map(:name) # same as above
63
62
 
64
63
  dataset.inject(0){|sum, r| sum + r[:value]}
65
- dataset.sum(:value) # same as above
64
+ dataset.sum(:value) # better
66
65
 
67
66
  == Filtering (see also {Dataset Filtering}[link:files/doc/dataset_filtering_rdoc.html])
68
67
 
@@ -101,7 +100,7 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
101
100
  DB[:items].where{(x > 5) & (y > 10)}.sql
102
101
  # SELECT * FROM items WHERE ((x > 5) AND (y > 10))
103
102
 
104
- DB[:items].where({:x => 1, :y => 2}.sql_or & Sequel.~(:z => 3)).sql
103
+ DB[:items].where(Sequel.or(:x => 1, :y => 2)) & Sequel.~(:z => 3)).sql
105
104
  # SELECT * FROM items WHERE (((x = 1) OR (y = 2)) AND (z != 3))
106
105
 
107
106
  === Mathematical operators
@@ -126,10 +125,13 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
126
125
  == Joins
127
126
 
128
127
  DB[:items].left_outer_join(:categories, :id => :category_id).sql
129
- # SELECT * FROM items LEFT OUTER JOIN categories ON categories.id = items.category_id
128
+ # SELECT * FROM items
129
+ # LEFT OUTER JOIN categories ON categories.id = items.category_id
130
130
 
131
131
  DB[:items].join(:categories, :id => :category_id).join(:groups, :id => :items__group_id)
132
- # SELECT * FROM items INNER JOIN categories ON categories.id = items.category_id INNER JOIN groups ON groups.id = items.group_id
132
+ # SELECT * FROM items
133
+ # INNER JOIN categories ON categories.id = items.category_id
134
+ # INNER JOIN groups ON groups.id = items.group_id
133
135
 
134
136
  == Aggregate functions methods
135
137
 
@@ -140,7 +142,7 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
140
142
  dataset.sum(:stock)
141
143
 
142
144
  dataset.group_and_count(:category)
143
- dataset.group(:category).select(:category, Sequel.function(:AVG, :price))
145
+ dataset.select_group(:category).select_append{avg(:price)}
144
146
 
145
147
  == SQL Functions / Literals
146
148
 
@@ -0,0 +1,89 @@
1
+ = Code Order
2
+
3
+ In Sequel, the order in which code is executed is important. This
4
+ guide provides the recommended way to order your Sequel code. Some
5
+ of these guidelines are not strictly necessary, but others are, and
6
+ this guide will be specific about which are strictly necessary.
7
+
8
+ == Require Sequel
9
+
10
+ This is sort of a no brainer, but you need to require the library
11
+ first. This is a strict requirement, none of the other code can
12
+ be executed unless the library has been required first. Example:
13
+
14
+ require 'sequel'
15
+
16
+ == Add Global Extensions
17
+
18
+ Global extensions are loaded with Sequel.extension, and affect
19
+ other parts of Sequel or the general ruby environment. It's not
20
+ necessary to load them first, but it is a recommended practice.
21
+ Example:
22
+
23
+ Sequel.extension :blank
24
+
25
+ == Add Extensions Applied to All Databases/Datasets
26
+
27
+ If you want database or datasets extensions applied to all databases
28
+ and datasets, you must use Sequel::Database.extension to load the
29
+ extension before connecting to a database. If you connect to a
30
+ database before using Sequel::Database.extension, it will not have
31
+ that extension loaded. Example:
32
+
33
+ Sequel::Database.extension :columns_introspection
34
+
35
+ == Connect to Databases
36
+
37
+ Connecting to a database is required before running any queries against
38
+ that database, or creating any datasets or models. You cannot create
39
+ model classes without having a database object created first. The
40
+ convention for an application with a single Database instance is to
41
+ store that instance in a constant named DB. Example:
42
+
43
+ DB = Sequel.connect('postgres://user:pass@host/database')
44
+
45
+ == Add Extensions Specific to a Database or All Datasets in that Database
46
+
47
+ If you want specific databases to use specific extensions, or have all
48
+ datasets in that database use a specific extension, you need to load that
49
+ extension into the database after creating it using
50
+ Sequel::Database#extension. Example:
51
+
52
+ DB.extension :pg_array
53
+
54
+ == Configure Global Model Behavior
55
+
56
+ If you want to change the configuration for all model classes, you must do
57
+ so before loading your model classes, as configuration is copied into the
58
+ subclass when model subclasses are created. Example:
59
+
60
+ Sequel::Model.raise_on_save_failure = false
61
+
62
+ == Add Global Model Plugins
63
+
64
+ If you want to load a plugin into all models classes, you must do so
65
+ before loading your model classes, as plugin specific data may need to be
66
+ copied into the subclass when model subclasses are created. Example:
67
+
68
+ Sequel::Model.plugin :prepared_statements
69
+
70
+ == Load Model Classes
71
+
72
+ After you have established a database connection, and configured your
73
+ global model configration and global plugins, you can load your model
74
+ classes. It's recommended to have a separate file for each model class,
75
+ unless the model classes are very simple. Example:
76
+
77
+ Dir['./models/*.rb'].each{|f| require f}
78
+
79
+ == Disconnect If Using Forking Webserver with Code Preloading
80
+
81
+ If you are using a forking webserver such as unicorn or passenger, with
82
+ a feature that loads your Sequel code before forking connections (code
83
+ preloading), then you must disconnect your database connections before
84
+ forking. If you don't do this, you can end up with child processes
85
+ sharing database connections and all sorts of weird behavior. Sequel
86
+ will automatically reconnect on an as needed basis in the child
87
+ processes, so you only need to do the following in the parent process:
88
+
89
+ DB.disconnect
@@ -8,7 +8,7 @@ Historically, Sequel added methods to many of the core classes, and usage of tho
8
8
  where(:column.like('A%')). # Symbol#like
9
9
  order({1=>2}.case(0, :a)) # Hash#case
10
10
 
11
- While Sequel never override any methods defined by ruby, it is possible that other libraries could define the same methods that Sequel defines, which could cause problems. Also, some rubyists do not like using libraries that add methods to the core classes.
11
+ While Sequel never overrode any methods defined by ruby, it is possible that other libraries could define the same methods that Sequel defines, which could cause problems. Also, some rubyists do not like using libraries that add methods to the core classes.
12
12
 
13
13
  Alternatives for the core extension methods where added to Sequel, so the query above could be written as:
14
14
 
@@ -22,7 +22,7 @@ Almost all of the core extension methods have a replacement on the Sequel module
22
22
 
23
23
  There is no recommendation on whether the core_extensions should be used or not. It is very rare that any of the methods added by core_extensions actually causes a problem, but some of them can make it more difficult to find other problems. For example, if you type:
24
24
 
25
- do_somehting if value | other_value
25
+ do_something if value | other_value
26
26
 
27
27
  while meaning to type:
28
28
 
@@ -236,7 +236,7 @@ Symbol#sql_function returns an SQL function call expression object:
236
236
 
237
237
  Alternative: Sequel.function:
238
238
 
239
- Sequel.function(:now, :a)
239
+ Sequel.function(:sum, :a)
240
240
 
241
241
  === String
242
242
 
@@ -79,25 +79,24 @@ FROM:: from, from_self
79
79
  JOIN:: join, left_join, right_join, full_join, natural_join, natural_left_join, natural_right_join, natural_full_join, cross_join, inner_join, left_outer_join, right_outer_join, full_outer_join, join_table
80
80
  WHERE:: where, filter, exclude, exclude_where, and, or, grep, invert, unfiltered
81
81
  GROUP:: group, group_by, group_and_count, select_group, ungrouped
82
- HAVING:: having, filter, exclude, exclude_having, and, or, grep, invert, unfiltered
82
+ HAVING:: having, exclude_having, invert, unfiltered
83
83
  ORDER:: order, order_by, order_append, order_prepend, order_more, reverse, reverse_order, unordered
84
84
  LIMIT:: limit, unlimited
85
85
  compounds:: union, intersect, except
86
86
  locking:: for_update, lock_style
87
87
  common table expressions:: with, with_recursive
88
- qualification:: qualify, qualify_to, qualify_to_first_source
89
- inserting:: set_defaults, set_overrides
90
- other:: clone, distinct, naked, server, with_sql
88
+ other:: clone, distinct, naked, qualify, server, with_sql
91
89
 
92
90
  === Methods that execute code on the database
93
91
 
94
92
  Most other dataset methods commonly used will execute the dataset's SQL on the database:
95
93
 
96
- SELECT (All Records):: all, each, map, to_hash, to_hash_groups, select_map, select_order_map, select_hash, select_hash_groups, to_csv
97
- SELECT (First Record):: first, last, get, []
94
+ SELECT (All Records):: all, each, map, to_hash, to_hash_groups, select_map, select_order_map, select_hash, select_hash_groups
95
+ SELECT (First Record):: first, last, [], single_record
96
+ SELECT (Single Value):: get, single_value
98
97
  SELECT (Aggregates):: count, avg, max, min, sum, range, interval
99
- INSERT:: insert, <<, import, multi_insert, insert_multiple
100
- UPDATE:: update, set, []=
98
+ INSERT:: insert, <<, import, multi_insert
99
+ UPDATE:: update
101
100
  DELETE:: delete
102
101
  other:: columns, columns!, truncate
103
102
 
@@ -140,11 +140,16 @@ Or against SQL functions:
140
140
 
141
141
  == String search functions
142
142
 
143
- You can search SQL strings using the Sequel.like method:
143
+ You can search SQL strings in a case sensitive manner using the Sequel.like method:
144
144
 
145
145
  items.where(Sequel.like(:name, 'Acme%')).sql
146
146
  #=> "SELECT * FROM items WHERE (name LIKE 'Acme%')"
147
147
 
148
+ You can search SQL strings in a case insensitive manner using the Sequel.ilike method:
149
+
150
+ items.where(Sequel.ilike(:name, 'Acme%')).sql
151
+ #=> "SELECT * FROM items WHERE (name ILIKE 'Acme%')"
152
+
148
153
  You can specify a Regexp as a like argument, but this will probably only work
149
154
  on PostgreSQL and MySQL:
150
155
 
@@ -163,7 +168,7 @@ You can concatenate SQL strings using Sequel.join:
163
168
  items.where(Sequel.join([:name, :comment]).like('%acme%')).sql
164
169
  #=> "SELECT * FROM items WHERE ((name || comment) LIKE 'Acme%')"
165
170
 
166
- Array#sql_string_join also takes a join argument:
171
+ Sequel.join also takes a join argument:
167
172
 
168
173
  items.filter(Sequel.join([:name, :comment], ' ').like('%acme%')).sql
169
174
  #=> "SELECT * FROM items WHERE ((name || ' ' || comment) LIKE 'Acme%')"
@@ -36,7 +36,7 @@ By default, if an invalid setter method call is attempted, Sequel raises a <tt>S
36
36
  # Instance level
37
37
  post.strict_param_setting = false
38
38
 
39
- These mass assignment methods have been around a long time, but starting in Sequel 3.12.0, the +set_fields+ and +update_fields+ methods were added, and these may be a better mass assignment choice for most users.
39
+ In addition to +set_only+ and +update_only+, Sequel also has +set_fields+ and +update_fields+ methods, and these may be a better mass assignment choice for most users.
40
40
  These methods take two arguments, the attributes hash as the first argument, and a single array of valid field names as the second argument:
41
41
 
42
42
  post.set_fields(params[:post], [:title, :body])
@@ -50,7 +50,6 @@ They work great for things like HTML forms where the form fields are static.
50
50
  +set_only+ and +update_only+ are designed for cases where you are not sure what fields are going to be present in the input, but still want to make sure only certain setter methods can be called.
51
51
  They work great for flexible APIs.
52
52
 
53
- Starting in Sequel 3.34.0, +set_fields+ and +update_fields+ take an optional argument hash, and currently handles the :missing option. With <tt>:missing=>:skip</tt>, +set_fields+ and +update_fields+ will just skip missing entries in the hash, allowing them to be used in flexible APIs. With <tt>:missing=>:raise</tt>, +set_fields+ and +update_fields+ will raise an error if one of the entries in the hash is missing, instead of just assigning the value to nil or whatever the hash's default value is. That allows stricter checks, similar to the :strict_param_checking setting for the default mass assignment methods.
53
+ +set_fields+ and +update_fields+ take an optional argument hash, and currently handles the :missing option. With <tt>:missing=>:skip</tt>, +set_fields+ and +update_fields+ will just skip missing entries in the hash, allowing them to be used in flexible APIs. With <tt>:missing=>:raise</tt>, +set_fields+ and +update_fields+ will raise an error if one of the entries in the hash is missing, instead of just assigning the value to nil or whatever the hash's default value is. That allows stricter checks, similar to the :strict_param_checking setting for the default mass assignment methods. You can use the <tt>Model.default_set_fields_options=</tt> method to set the default options to use for +set_fields+ and +update_fields+ on a global or per-model basis.
54
54
 
55
55
  In all of the mass assignment cases, methods starting with +set+ will set the attributes without saving the object, while methods starting with +update+ will set the attributes and then save the changes to the object.
56
-
@@ -100,7 +100,7 @@ from Sacramento, CA, USA, but now you want to branch out and include artists in
100
100
  Sequel.migration do
101
101
  up do
102
102
  add_column :artists, :location, String
103
- self[:artists].update(:location=>'Sacramento')
103
+ from(:artists).update(:location=>'Sacramento')
104
104
  end
105
105
 
106
106
  down do
@@ -114,10 +114,10 @@ because future artists should not be assumed to come from Sacramento. In the +d
114
114
  just drops the +location+ column from the +artists+ table, reversing the actions of the up
115
115
  block.
116
116
 
117
- Note that when updating the +artists+ table in the update, a plain dataset is used, <tt>self[:artists]</tt>.
117
+ Note that when updating the +artists+ table in the update, a plain dataset is used, <tt>from(:artists)</tt>.
118
118
  This looks a little weird, but you need to be aware that inside an up or +down+ block in a migration,
119
119
  self always refers to the <tt>Sequel::Database</tt> object that the migration is being applied to.
120
- Since <tt>Database#[]</tt> creates datasets, using <tt>self[:artists]</tt> inside the +up+ block creates
120
+ Since <tt>Database#from</tt> creates datasets, using <tt>from(:artists)</tt> inside the +up+ block creates
121
121
  a dataset on the database representing all columns in the +artists+ table, and updates it to set the
122
122
  +location+ column to <tt>'Sacramento'</tt>. You should avoid referencing the <tt>Sequel::Database</tt>
123
123
  object directly in your migration, and always use self to reference it, otherwise you may run into problems.
@@ -130,7 +130,7 @@ to create their development database.
130
130
  == The +migration+ extension
131
131
 
132
132
  The migration code is not technically part of the core of Sequel. It's not loaded by default as it
133
- is only useful in specific cases. It is one of the built-in extensions, which receive the same
133
+ is only useful in specific cases. It is one of the extensions that ship with Sequel, which receive the same
134
134
  level of support as Sequel's core.
135
135
 
136
136
  If you want to play with Sequel's migration tools without using the <tt>bin/sequel</tt> tool, you
@@ -240,7 +240,7 @@ the +TimestampMigrator+. They both have plusses and minuses:
240
240
 
241
241
  * Simpler, uses migration versions starting with 1
242
242
  * Doesn't allow duplicate migrations
243
- * Doesn't allow missing migrations
243
+ * Doesn't allow missing migrations by default
244
244
  * Just stores the version of the last migration run
245
245
  * Good for single developer or small teams with close
246
246
  communication
@@ -255,7 +255,7 @@ the +TimestampMigrator+. They both have plusses and minuses:
255
255
  * Allows missing migrations (since you obviously don't have one every second)
256
256
  * Stores the file names of all applied migrations
257
257
  * Good for large teams without close communication
258
- * Higher risk of undected conflicting migrations
258
+ * Higher risk of undetected conflicting migrations
259
259
  * Does not require manual merging of simultaneous migrations
260
260
 
261
261
  === Filenames
@@ -293,7 +293,7 @@ to worry about that issue until the 1000th migration:
293
293
  009_do_something.rb
294
294
  010_do_something_else.rb
295
295
 
296
- It should be fairly obvious, but migrations start at 1, not 0. The migration version number 0
296
+ Migrations start at 1, not 0. The migration version number 0
297
297
  is important though, as it is used to mean that all migrations should be unapplied (i.e. all
298
298
  +down+ blocks run). In Sequel, you can do that with:
299
299
 
@@ -349,7 +349,7 @@ So for unrelated migrations, the +TimestampMigrator+ works fine. However, let's
349
349
  migrations are related, in such a way that if Bob's is run first, Alice's will fail. In this
350
350
  case, the +TimestampMigrator+ would not raise an error when Bob merges Alice's changes, since
351
351
  Bob ran his migration first. However, it would raise an error when Alice runs Bob's migration,
352
- and could leave the database in an inconsistant state if the database doesn't support transactional
352
+ and could leave the database in an inconsistent state if the database doesn't support transactional
353
353
  schema changes.
354
354
 
355
355
  With the +TimestampMigrator+, you are trading reliability for convenience. That's possibly a valid
@@ -17,7 +17,7 @@ Model hooks, also known as model callbacks, are used to specify actions that occ
17
17
  end
18
18
  end
19
19
 
20
- The one important thing to note here is the call to +super+ inside the hook. Whenever you override one of Sequel::Model's methods, you should be calling +super+ to get the default behavior. Many of Sequel's built in plugins work by overriding the hook methods and calling +super+. If you use these plugins and override the hook methods but do not call +super+, it's likely the plugins will not work correctly.
20
+ The one important thing to note here is the call to +super+ inside the hook. Whenever you override one of Sequel::Model's methods, you should be calling +super+ to get the default behavior. Many of the plugins that ship with Sequel work by overriding the hook methods and calling +super+. If you use these plugins and override the hook methods but do not call +super+, it's likely the plugins will not work correctly.
21
21
 
22
22
  == Available Hooks
23
23
 
@@ -67,8 +67,6 @@ Sequel calls hooks in the following order when destroying an existing object:
67
67
 
68
68
  Note that these hooks are only called when using <tt>Model#destroy</tt>, they are not called if you use <tt>Model#delete</tt>.
69
69
 
70
- <tt>Sequel::Model</tt> does support a few additional hooks. One is +after_intialize+, which is called after the model object has been initalized. It can be used to set default attribute values for new objects, since by default new <tt>Sequel::Model</tt> objects have no attributes, and the attributes are not filled in until the model object is saved. You should be careful when you are using +after_initialize+, since it is called for every created record. So if you run a query that returns 1000 model objects, it will be called 1000 times. If you only want to change the behavior for new records, you can override the +initialize_set+ private method, which is called with the hash passed to +initialize+.
71
-
72
70
  == Special Hook-Related Instance Variables
73
71
 
74
72
  For after_save hooks, a @was_new instance variable is present that indicates whether the record was a new record that was just inserted, or an existing record that was updated. Sequel marks a record as existing as soon as it inserts the record, so in an after_save or after_create hook, the instance is no longer considered new. You have to check @was_new to see if the record was inserted. This exists so that you don't have to have separate after_create and after_update hooks that are mostly the same and only differ slightly depending on whether the record was a new record.
@@ -114,7 +112,7 @@ However, skipping hooks is a bad idea in general and should be avoided. As ment
114
112
 
115
113
  The +this+ dataset works just like any other dataset, so you can call +update+ on it to modify it:
116
114
 
117
- album.this.update(:copies_sold=>:copies_sold + 1)
115
+ album.this.update(:copies_sold=>album.copies_sold + 1))
118
116
 
119
117
  If you want to insert a row into the model's table without running the creation hooks, you can use <tt>Model.insert</tt> instead of <tt>Model.create</tt>:
120
118
 
@@ -240,10 +238,16 @@ Likewise, let's say that upon retrieval, you associate an object with a file des
240
238
  end
241
239
  end
242
240
 
243
- == +hook_class_methods+
241
+ == Hook related plugins
242
+
243
+ === +instance_hooks+
244
+
245
+ Sequel also ships with an +instance_hooks+ plugin that allows you to define before and after hooks on a per instance basis. It's very useful as it allows you to delay action on an instance until before or after saving. This can be important if you want to modify a group of related objects together (which is how the +nested_attributes+ plugin uses +instance_hooks+).
246
+
247
+ === +hook_class_methods+
244
248
 
245
249
  While it's recommended to write your hooks as instance methods, Sequel ships with a +hook_class_methods+ plugin that allows you to define hooks via class methods. It exists mostly for legacy compatibility, but is still supported. However, it does not implement around hooks.
246
250
 
247
- == +instance_hooks+
251
+ === +after_initialize+
248
252
 
249
- Sequel also ships with an +instance_hooks+ plugin that allows you to define before and after hooks on a per instance basis. It's very useful as it allows you to delay action on an instance until before or after saving. This can be important if you want to modify a group of related objects together (which is how the +nested_attributes+ plugin uses +instance_hooks+).
253
+ The after_initialize plugin adds an after_initialize hook, that is called for all model instances on creation (both new instances and instances retrieved from the database). It exists mostly for legacy compatibility, but it is still supported.
@@ -3,7 +3,7 @@
3
3
  Sequel's dataset layer is mostly structured as an DSL, so it often obscures
4
4
  what actual objects are being used. For example, you don't usually create
5
5
  Sequel objects by calling #new on the object's class (other than Sequel::Model
6
- subclasses). However, just as almost everything in ruby is an object, all
6
+ instances). However, just as almost everything in ruby is an object, all
7
7
  the methods you call in Sequel deal with objects behind the scenes.
8
8
 
9
9
  There are five main types of Sequel-specific objects that you deal with in
@@ -377,7 +377,7 @@ take arguments. Still, it's possible they are still useful in some code:
377
377
 
378
378
  Sequel::SQL::ColumnAll.new(:table) # "table".*
379
379
 
380
- The following shortcut exists for creating Sequel::SQL::Cast objects:
380
+ The following shortcut exists for creating Sequel::SQL::ColumnAll objects:
381
381
 
382
382
  Sequel.expr(:table).*
383
383
  :table.* # core_extensions extension
@@ -12,7 +12,7 @@ The connection options needed depend on the adapter being used, though most adap
12
12
  share the same basic connection options.
13
13
 
14
14
  If you are only connecting to a single database, it is recommended that you store the
15
- database object in a constant named DB. This should never be required, but it is the
15
+ database object in a constant named DB. This is not required, but it is the
16
16
  convention that most Sequel code uses.
17
17
 
18
18
  == Using the Sequel.connect method
@@ -68,9 +68,7 @@ These options are shared by all adapters unless otherwise noted.
68
68
 
69
69
  :adapter :: The adapter to use
70
70
  :database :: The name of the database to which to connect
71
- :default_schema :: The database schema to use in schema_modification and introspection.
72
71
  :host :: The hostname of the database server to which to connect
73
- :logger :: An array of SQL loggers to log to
74
72
  :loggers :: An array of SQL loggers to log to
75
73
  :password :: The password for the user account
76
74
  :servers :: A hash with symbol keys and hash or proc values, used with master/slave/partitioned database configurations
@@ -98,7 +96,7 @@ Requires: win32ole
98
96
 
99
97
  The ADO adapter provides connectivity to ADO databases in Windows. It relies
100
98
  on WIN32OLE library, so it isn't usable on other operating systems (except
101
- possibly through WINE, but that's fairly unlikely).
99
+ possibly through WINE, but that's unlikely).
102
100
 
103
101
  The following options are supported:
104
102
 
@@ -239,7 +237,7 @@ Requires: java
239
237
  Houses Sequel's JDBC support when running on JRuby.
240
238
  Support for individual database types is done using sub adapters.
241
239
  There are currently subadapters for PostgreSQL, MySQL, SQLite, H2, HSQLDB, Derby,
242
- Oracle, MSSQL, JTDS, AS400, Progress, Firebird, Informix, and DB2. For PostgreSQL, MySQL, SQLite, H2, Derby,
240
+ Oracle, MSSQL, JTDS, AS400, Progress, Firebird, Informix, and DB2. For PostgreSQL, MySQL, SQLite, H2, HSQLDB, Derby,
243
241
  and JTDS, this can use the jdbc-* gem, for the others you need to have the .jar in your CLASSPATH
244
242
  or load the Java class manually before calling Sequel.connect.
245
243
 
@@ -396,7 +394,7 @@ The following additional options are supported:
396
394
 
397
395
  === swift
398
396
 
399
- swift is a ruby 1.9 only library, so you'll need to be running ruby 1.9. It
397
+ swift is a ruby 1.9+ library, so you'll need to be running ruby 1.9+. It
400
398
  can connect to SQLite, MySQL, and PostgreSQL, and you must specify which
401
399
  database using the db_type option.
402
400
 
@@ -416,8 +414,7 @@ Examples:
416
414
 
417
415
  Requires: tiny_tds
418
416
 
419
- Because the underscore is not a valid character in a URI schema, the adapter
420
- is named tinytds instead of tiny_tds. The connection options are passed directly
417
+ The connection options are passed directly
421
418
  to tiny_tds, except that the tiny_tds :username option is set to
422
419
  the Sequel :user option. If you want to use an entry in the freetds.conf file, you
423
420
  should specify the :dataserver option with that name as the value. Some other
@@ -432,11 +429,5 @@ Other Sequel specific options:
432
429
  text or blob values via tinytds, you should use this option or modify
433
430
  your freetds.conf file.
434
431
 
435
- For highest performance, you should disable any identifier output method when
436
- using the tinytds adapter, which probably means disabling any identifier input method
437
- as well. The default for Microsoft SQL Server is to :downcase identifiers on output
438
- and :upcase them on input, so the highest performance will require changing the setting
439
- from the default.
440
-
441
432
  The Sequel tinytds adapter requires tiny_tds >= 0.4.5, and if you are using FreeTDS
442
433
  0.91, you must at least be using 0.91rc2 (0.91rc1 does not work).