sequel 5.80.0 → 5.92.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 (205) hide show
  1. checksums.yaml +4 -4
  2. data/bin/sequel +9 -4
  3. data/lib/sequel/adapters/ado.rb +1 -1
  4. data/lib/sequel/adapters/ibmdb.rb +1 -0
  5. data/lib/sequel/adapters/jdbc/db2.rb +2 -2
  6. data/lib/sequel/adapters/jdbc/derby.rb +3 -3
  7. data/lib/sequel/adapters/jdbc/h2.rb +2 -2
  8. data/lib/sequel/adapters/jdbc/hsqldb.rb +2 -2
  9. data/lib/sequel/adapters/jdbc/jtds.rb +2 -2
  10. data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
  11. data/lib/sequel/adapters/jdbc/oracle.rb +5 -5
  12. data/lib/sequel/adapters/jdbc/postgresql.rb +5 -5
  13. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +6 -6
  14. data/lib/sequel/adapters/jdbc/sqlite.rb +2 -2
  15. data/lib/sequel/adapters/jdbc/sqlserver.rb +2 -2
  16. data/lib/sequel/adapters/jdbc.rb +8 -8
  17. data/lib/sequel/adapters/mysql2.rb +8 -1
  18. data/lib/sequel/adapters/shared/access.rb +1 -0
  19. data/lib/sequel/adapters/shared/db2.rb +1 -1
  20. data/lib/sequel/adapters/shared/mssql.rb +18 -5
  21. data/lib/sequel/adapters/shared/mysql.rb +8 -4
  22. data/lib/sequel/adapters/shared/oracle.rb +1 -0
  23. data/lib/sequel/adapters/shared/postgres.rb +106 -13
  24. data/lib/sequel/adapters/shared/sqlite.rb +4 -2
  25. data/lib/sequel/adapters/sqlite.rb +4 -0
  26. data/lib/sequel/adapters/trilogy.rb +1 -2
  27. data/lib/sequel/connection_pool/sharded_threaded.rb +26 -10
  28. data/lib/sequel/connection_pool/threaded.rb +26 -10
  29. data/lib/sequel/connection_pool.rb +2 -2
  30. data/lib/sequel/core.rb +15 -0
  31. data/lib/sequel/database/connecting.rb +20 -26
  32. data/lib/sequel/database/dataset_defaults.rb +3 -3
  33. data/lib/sequel/database/misc.rb +46 -10
  34. data/lib/sequel/database/query.rb +11 -11
  35. data/lib/sequel/database/schema_generator.rb +8 -0
  36. data/lib/sequel/database/schema_methods.rb +17 -1
  37. data/lib/sequel/dataset/actions.rb +9 -1
  38. data/lib/sequel/dataset/deprecated_singleton_class_methods.rb +1 -1
  39. data/lib/sequel/dataset/prepared_statements.rb +2 -1
  40. data/lib/sequel/dataset/query.rb +9 -5
  41. data/lib/sequel/dataset/sql.rb +25 -5
  42. data/lib/sequel/extensions/caller_logging.rb +2 -0
  43. data/lib/sequel/extensions/connection_validator.rb +15 -10
  44. data/lib/sequel/extensions/dataset_run.rb +41 -0
  45. data/lib/sequel/extensions/migration.rb +23 -3
  46. data/lib/sequel/extensions/null_dataset.rb +2 -2
  47. data/lib/sequel/extensions/pg_auto_parameterize.rb +1 -1
  48. data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +93 -10
  49. data/lib/sequel/extensions/pg_enum.rb +3 -3
  50. data/lib/sequel/extensions/pg_json_ops.rb +642 -9
  51. data/lib/sequel/extensions/pg_row.rb +3 -1
  52. data/lib/sequel/extensions/pg_schema_caching.rb +90 -0
  53. data/lib/sequel/extensions/provenance.rb +2 -0
  54. data/lib/sequel/extensions/query_blocker.rb +172 -0
  55. data/lib/sequel/extensions/schema_caching.rb +24 -9
  56. data/lib/sequel/extensions/schema_dumper.rb +16 -4
  57. data/lib/sequel/extensions/sqlite_json_ops.rb +1 -1
  58. data/lib/sequel/extensions/stdio_logger.rb +48 -0
  59. data/lib/sequel/extensions/string_agg.rb +17 -4
  60. data/lib/sequel/extensions/temporarily_release_connection.rb +178 -0
  61. data/lib/sequel/extensions/virtual_row_method_block.rb +1 -0
  62. data/lib/sequel/model/associations.rb +28 -3
  63. data/lib/sequel/model/base.rb +67 -18
  64. data/lib/sequel/plugins/association_pks.rb +1 -1
  65. data/lib/sequel/plugins/column_encryption.rb +1 -1
  66. data/lib/sequel/plugins/composition.rb +1 -1
  67. data/lib/sequel/plugins/defaults_setter.rb +16 -4
  68. data/lib/sequel/plugins/enum.rb +1 -1
  69. data/lib/sequel/plugins/forbid_lazy_load.rb +14 -1
  70. data/lib/sequel/plugins/input_transformer.rb +1 -1
  71. data/lib/sequel/plugins/inspect_pk.rb +44 -0
  72. data/lib/sequel/plugins/instance_filters.rb +4 -1
  73. data/lib/sequel/plugins/inverted_subsets.rb +1 -0
  74. data/lib/sequel/plugins/lazy_attributes.rb +1 -1
  75. data/lib/sequel/plugins/nested_attributes.rb +10 -5
  76. data/lib/sequel/plugins/optimistic_locking.rb +2 -0
  77. data/lib/sequel/plugins/paged_operations.rb +5 -2
  78. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +6 -1
  79. data/lib/sequel/plugins/pg_auto_validate_enums.rb +88 -0
  80. data/lib/sequel/plugins/pg_eager_any_typed_array.rb +95 -0
  81. data/lib/sequel/plugins/rcte_tree.rb +1 -1
  82. data/lib/sequel/plugins/serialization.rb +11 -5
  83. data/lib/sequel/plugins/sql_comments.rb +7 -2
  84. data/lib/sequel/plugins/static_cache_cache.rb +50 -13
  85. data/lib/sequel/plugins/subset_conditions.rb +85 -5
  86. data/lib/sequel/plugins/subset_static_cache.rb +263 -0
  87. data/lib/sequel/plugins/tactical_eager_loading.rb +6 -2
  88. data/lib/sequel/plugins/validate_associated.rb +1 -1
  89. data/lib/sequel/sql.rb +16 -6
  90. data/lib/sequel/version.rb +1 -1
  91. metadata +12 -234
  92. data/CHANGELOG +0 -1355
  93. data/README.rdoc +0 -936
  94. data/doc/advanced_associations.rdoc +0 -884
  95. data/doc/association_basics.rdoc +0 -1859
  96. data/doc/bin_sequel.rdoc +0 -146
  97. data/doc/cheat_sheet.rdoc +0 -255
  98. data/doc/code_order.rdoc +0 -102
  99. data/doc/core_extensions.rdoc +0 -405
  100. data/doc/dataset_basics.rdoc +0 -96
  101. data/doc/dataset_filtering.rdoc +0 -222
  102. data/doc/extensions.rdoc +0 -77
  103. data/doc/fork_safety.rdoc +0 -84
  104. data/doc/mass_assignment.rdoc +0 -98
  105. data/doc/migration.rdoc +0 -660
  106. data/doc/model_dataset_method_design.rdoc +0 -129
  107. data/doc/model_hooks.rdoc +0 -254
  108. data/doc/model_plugins.rdoc +0 -270
  109. data/doc/mssql_stored_procedures.rdoc +0 -43
  110. data/doc/object_model.rdoc +0 -563
  111. data/doc/opening_databases.rdoc +0 -436
  112. data/doc/postgresql.rdoc +0 -611
  113. data/doc/prepared_statements.rdoc +0 -144
  114. data/doc/querying.rdoc +0 -1070
  115. data/doc/reflection.rdoc +0 -120
  116. data/doc/release_notes/5.0.0.txt +0 -159
  117. data/doc/release_notes/5.1.0.txt +0 -31
  118. data/doc/release_notes/5.10.0.txt +0 -84
  119. data/doc/release_notes/5.11.0.txt +0 -83
  120. data/doc/release_notes/5.12.0.txt +0 -141
  121. data/doc/release_notes/5.13.0.txt +0 -27
  122. data/doc/release_notes/5.14.0.txt +0 -63
  123. data/doc/release_notes/5.15.0.txt +0 -39
  124. data/doc/release_notes/5.16.0.txt +0 -110
  125. data/doc/release_notes/5.17.0.txt +0 -31
  126. data/doc/release_notes/5.18.0.txt +0 -69
  127. data/doc/release_notes/5.19.0.txt +0 -28
  128. data/doc/release_notes/5.2.0.txt +0 -33
  129. data/doc/release_notes/5.20.0.txt +0 -89
  130. data/doc/release_notes/5.21.0.txt +0 -87
  131. data/doc/release_notes/5.22.0.txt +0 -48
  132. data/doc/release_notes/5.23.0.txt +0 -56
  133. data/doc/release_notes/5.24.0.txt +0 -56
  134. data/doc/release_notes/5.25.0.txt +0 -32
  135. data/doc/release_notes/5.26.0.txt +0 -35
  136. data/doc/release_notes/5.27.0.txt +0 -21
  137. data/doc/release_notes/5.28.0.txt +0 -16
  138. data/doc/release_notes/5.29.0.txt +0 -22
  139. data/doc/release_notes/5.3.0.txt +0 -121
  140. data/doc/release_notes/5.30.0.txt +0 -20
  141. data/doc/release_notes/5.31.0.txt +0 -148
  142. data/doc/release_notes/5.32.0.txt +0 -46
  143. data/doc/release_notes/5.33.0.txt +0 -24
  144. data/doc/release_notes/5.34.0.txt +0 -40
  145. data/doc/release_notes/5.35.0.txt +0 -56
  146. data/doc/release_notes/5.36.0.txt +0 -60
  147. data/doc/release_notes/5.37.0.txt +0 -30
  148. data/doc/release_notes/5.38.0.txt +0 -28
  149. data/doc/release_notes/5.39.0.txt +0 -19
  150. data/doc/release_notes/5.4.0.txt +0 -80
  151. data/doc/release_notes/5.40.0.txt +0 -40
  152. data/doc/release_notes/5.41.0.txt +0 -25
  153. data/doc/release_notes/5.42.0.txt +0 -136
  154. data/doc/release_notes/5.43.0.txt +0 -98
  155. data/doc/release_notes/5.44.0.txt +0 -32
  156. data/doc/release_notes/5.45.0.txt +0 -34
  157. data/doc/release_notes/5.46.0.txt +0 -87
  158. data/doc/release_notes/5.47.0.txt +0 -59
  159. data/doc/release_notes/5.48.0.txt +0 -14
  160. data/doc/release_notes/5.49.0.txt +0 -59
  161. data/doc/release_notes/5.5.0.txt +0 -61
  162. data/doc/release_notes/5.50.0.txt +0 -78
  163. data/doc/release_notes/5.51.0.txt +0 -47
  164. data/doc/release_notes/5.52.0.txt +0 -87
  165. data/doc/release_notes/5.53.0.txt +0 -23
  166. data/doc/release_notes/5.54.0.txt +0 -27
  167. data/doc/release_notes/5.55.0.txt +0 -21
  168. data/doc/release_notes/5.56.0.txt +0 -51
  169. data/doc/release_notes/5.57.0.txt +0 -23
  170. data/doc/release_notes/5.58.0.txt +0 -31
  171. data/doc/release_notes/5.59.0.txt +0 -73
  172. data/doc/release_notes/5.6.0.txt +0 -31
  173. data/doc/release_notes/5.60.0.txt +0 -22
  174. data/doc/release_notes/5.61.0.txt +0 -43
  175. data/doc/release_notes/5.62.0.txt +0 -132
  176. data/doc/release_notes/5.63.0.txt +0 -33
  177. data/doc/release_notes/5.64.0.txt +0 -50
  178. data/doc/release_notes/5.65.0.txt +0 -21
  179. data/doc/release_notes/5.66.0.txt +0 -24
  180. data/doc/release_notes/5.67.0.txt +0 -32
  181. data/doc/release_notes/5.68.0.txt +0 -61
  182. data/doc/release_notes/5.69.0.txt +0 -26
  183. data/doc/release_notes/5.7.0.txt +0 -108
  184. data/doc/release_notes/5.70.0.txt +0 -35
  185. data/doc/release_notes/5.71.0.txt +0 -21
  186. data/doc/release_notes/5.72.0.txt +0 -33
  187. data/doc/release_notes/5.73.0.txt +0 -66
  188. data/doc/release_notes/5.74.0.txt +0 -45
  189. data/doc/release_notes/5.75.0.txt +0 -35
  190. data/doc/release_notes/5.76.0.txt +0 -86
  191. data/doc/release_notes/5.77.0.txt +0 -63
  192. data/doc/release_notes/5.78.0.txt +0 -67
  193. data/doc/release_notes/5.79.0.txt +0 -28
  194. data/doc/release_notes/5.8.0.txt +0 -170
  195. data/doc/release_notes/5.80.0.txt +0 -40
  196. data/doc/release_notes/5.9.0.txt +0 -99
  197. data/doc/schema_modification.rdoc +0 -679
  198. data/doc/security.rdoc +0 -443
  199. data/doc/sharding.rdoc +0 -286
  200. data/doc/sql.rdoc +0 -648
  201. data/doc/testing.rdoc +0 -190
  202. data/doc/thread_safety.rdoc +0 -15
  203. data/doc/transactions.rdoc +0 -250
  204. data/doc/validations.rdoc +0 -558
  205. data/doc/virtual_rows.rdoc +0 -265
@@ -1,265 +0,0 @@
1
- = Virtual Row Blocks
2
-
3
- Dataset methods where, order, and select all take blocks that are referred to as
4
- virtual row blocks. Many other dataset methods pass the blocks
5
- they are given into one of those three methods, so there are actually
6
- many Sequel::Dataset methods that take virtual row blocks.
7
-
8
- == Why Virtual Rows
9
-
10
- Virtual rows offer a less verbose way to express many queries. For example,
11
- by default if you want to express an inequality filter in Sequel, you can do:
12
-
13
- dataset.where(Sequel[:a] > Sequel.function(:b, :c))
14
- # WHERE (a > b(c))
15
-
16
- With virtual rows, you can use the less verbose:
17
-
18
- dataset.where{a > b(c)}
19
- # WHERE (a > b(c))
20
-
21
- == Regular Procs vs Instance Evaled Procs
22
-
23
- Virtual row blocks behave differently depending on whether the block accepts
24
- an argument. If the block accepts an argument, it is called with an instance
25
- of Sequel::SQL::VirtualRow. If it does not accept an argument, it is
26
- evaluated in the <em> context of an instance </em> of Sequel::SQL::VirtualRow.
27
-
28
- ds = DB[:items]
29
- # Regular block
30
- ds.where{|o| o.column > 1}
31
- # WHERE (column > 1)
32
-
33
- # Instance-evaled block
34
- ds.where{column > 1}
35
- # WHERE (column > 1)
36
-
37
- If you aren't familiar with the difference between regular blocks and instance
38
- evaled blocks, inside regular blocks methods called without an explicit receiver call
39
- the method on the receiver in the surrounding scope, while instance
40
- evaled blocks call the method on the receiver of the instance_eval call (the
41
- Sequel::SQL::VirtualRow instance in this case).
42
-
43
- in both cases, local variables available in the surrounding scope will be available
44
- inside the block. However, instance variables in the surrounding scope will not
45
- be available inside the block if using an instance evaled block, and methods called
46
- without an explicit receiver inside an instance evaled block will not call
47
- methods in the surrounding scope. For example:
48
-
49
- def self.a
50
- 42
51
- end
52
- b = 32
53
- @d = 100
54
-
55
- # Regular block
56
- ds.where{|o| o.c > a - b + @d}
57
- # WHERE (c > 110)
58
-
59
- # Instance-evaled block
60
- ds.where{c > a - b + @d}
61
- # WHERE (c > ((a - 32) + NULL))
62
-
63
- There are three related differences here:
64
-
65
- * Regular blocks use +o.c+ instead of just +c+
66
- * +a+ results in 42 in the regular block, but creates an expression object in the instance evaled block
67
- * @d results in 100 in the regular block, but nil in the instance evaled block
68
-
69
- In the regular block, you need to call +c+ with an explicit receiver (the virtual
70
- row block argument), while in the instance evaled block +c+ can be called directly,
71
- as the default receiver has changed inside the block.
72
-
73
- For +a+, note how ruby calls the method on
74
- the receiver of the surrounding scope in the regular block, which returns an integer,
75
- and does the subtraction before Sequel gets access to it. In the instance evaled
76
- block, calling +a+ without a receiver calls the a method on the VirtualRow instance.
77
- For @d, note that in a regular block, the value hasn't changed, but in the instance evaled
78
- block, instance variable access returns nil.
79
- For +b+, note that it operates the same in both cases, as it is a local variable.
80
-
81
- The choice for whether to use a regular block or an instance evaled block is
82
- up to you. The same things can be accomplished with both.
83
- Instance evaled block tend to produce shorter code, but by modifying the scope
84
- can be more difficult to understand.
85
-
86
- If you are not sure which to use, use instance evaled blocks unless you need to
87
- call methods or access instance variables of the surrounding scope inside the block.
88
-
89
- == Local Variables vs Method Calls
90
-
91
- If you have a method that accepts 0 arguments and has the same name as a local
92
- variable, you can call it with () to differentiate the method call from the
93
- local variable access. This is mostly useful in instance evaled blocks:
94
-
95
- b = 32
96
- ds.where{b() > b}
97
- # WHERE b > 32
98
-
99
- It's also possible to use an explicit self receiver in instance evaled blocks:
100
-
101
- b = 32
102
- ds.where{self.b > b}
103
- # WHERE b > 32
104
-
105
-
106
- == VirtualRow Methods
107
-
108
- VirtualRow is a class that returns SQL::Identifiers or SQL::Functions depending
109
- on how it is called.
110
-
111
- == SQL::Identifiers - Regular columns
112
-
113
- SQL::Identifiers can be thought of as regular column references in SQL,
114
- not qualified by any table. You get an SQL::Identifier if the method is called
115
- without arguments:
116
-
117
- ds.where{|o| o.column > 1}
118
- ds.where{column > 1}
119
- # WHERE (column > 1)
120
-
121
- == SQL::QualifiedIdentifiers - Qualified columns
122
-
123
- You can qualified identifiers by calling #[] on an identifier:
124
-
125
- ds.where{|o| o.table[:column] > 1}
126
- ds.where{table[:column] > 1}
127
- # WHERE table.column > 1
128
-
129
- == SQL::Functions - SQL function calls
130
-
131
- SQL::Functions can be thought of as function calls in SQL. You get a simple
132
- function call if you call a method with arguments:
133
-
134
- ds.where{|o| o.function(1) > 1}
135
- ds.where{function(1) > 1}
136
- # WHERE function(1) > 1
137
-
138
- To call a SQL function with multiple arguments, just use those arguments in
139
- your function call:
140
-
141
- ds.where{|o| o.function(1, o.a) > 1}
142
- ds.where{function(1, a) > 1}
143
- # WHERE function(1, a) > 1
144
-
145
- If the SQL function does not accept any arguments, create an identifier, then
146
- call the function method on it to produce a function:
147
-
148
- ds.select{|o| o.version.function}
149
- ds.select{version.function}
150
- # SELECT version()
151
-
152
- To use the SQL wildcard (*) as the sole argument in a function call, create a
153
- function without arguments, then call the * method on the function:
154
-
155
- ds.select{|o| o.count.function.*}
156
- ds.select{count.function.*}
157
- # SELECT count(*)
158
-
159
- To append the DISTINCT keyword before the method arguments, just call the
160
- distinct method on the returned Function:
161
-
162
- ds.select{|o| o.count(o.col1).distinct}
163
- ds.select{count(col1).distinct}
164
- # SELECT count(DISTINCT col1)
165
-
166
- ds.select{|o| o.count(o.col1, o.col2).distinct}
167
- ds.select{count(col1, col2).distinct}
168
- # SELECT count(DISTINCT col1, col2)
169
-
170
- == SQL::Functions with windows - SQL window function calls
171
-
172
- To create a window function call, just call the over method on the Function
173
- object returned, with the options for the window:
174
-
175
- ds.select{|o| o.rank.function.over}
176
- ds.select{rank.function.over}
177
- # SELECT rank() OVER ()
178
-
179
- ds.select{|o| o.count.function.*.over}
180
- ds.select{count.function.*.over}
181
- # SELECT count(*) OVER ()
182
-
183
- ds.select{|o| o.sum(o.col1).over(partition: o.col2, order: o.col3)}
184
- ds.select{sum(col1).over(partition: col2, order: col3)}
185
- # SELECT sum(col1) OVER (PARTITION BY col2 ORDER BY col3)
186
-
187
- == Operators
188
-
189
- VirtualRows use method_missing to handle almost all method calls. Since the
190
- objects given by method_missing are SQL::Identifiers or SQL::Functions, you can use all operators that they provide (see
191
- DatasetFiltering[http://sequel.jeremyevans.net/rdoc/files/doc/dataset_filtering_rdoc.html#label-Filtering+using+expressions]):
192
-
193
- ds.select{|o| o.price - 100}
194
- ds.select{price - 100}
195
- # SELECT (price - 100)
196
-
197
- ds.where{|o| (o.price < 200) & (o.tax * 100 >= 23)}
198
- ds.where{(price < 200) & (tax * 100 >= 0.23)}
199
- # WHERE ((price < 200) AND ((tax * 100) >= 0.23))
200
-
201
- However, VirtualRows have special handling of some operator methods to make
202
- certain things easier. The operators all use a prefix form.
203
-
204
- === Math Operators
205
-
206
- The standard +, -, *, and / mathematical operators are defined:
207
-
208
- ds.select{|o| o.-(1, o.a).as(b)}
209
- ds.select{self.-(1, a).as(b)}
210
- # SELECT (1 - a) AS b
211
-
212
- === Boolean Operators
213
-
214
- The & and | methods are defined to use AND and OR:
215
-
216
- ds.where{|o| o.&({a: :b}, :c)}
217
- ds.where{self.&({a: :b}, :c)}
218
- # WHERE ((a = b) AND c)
219
-
220
- The ~ method is defined to do inversion:
221
-
222
- ds.where{|o| o.~({a: 1, b: 2})}
223
- ds.where{self.~({a: 1, b: 2})}
224
- # WHERE ((a != 1) OR (b != 2))
225
-
226
- === Inequality Operators
227
-
228
- The standard >, <, >=, and <= inequality operators are defined:
229
-
230
- ds.where{|o| o.>(1, :c)}
231
- ds.where{self.>(1, :c)}
232
- # WHERE (1 > c)
233
-
234
- == Returning multiple values
235
-
236
- It's common when using select and order virtual row blocks to want to
237
- return multiple values. If you want to do that, you just need to return an
238
- array:
239
-
240
- ds.select{|o| [o.column1, o.sum(o.column2).as(o.sum)]}
241
- ds.select{[column1, sum(column2).as(sum)]}
242
- # SELECT column1, sum(column2) AS sum
243
-
244
- Note that if you forget the array brackets, you'll end up with a syntax error:
245
-
246
- # Invalid ruby syntax
247
- ds.select{|o| o.column1, o.sum(o.column2).as(o.sum)}
248
- ds.select{column1, sum(column2).as(sum)}
249
-
250
- == Split symbols
251
-
252
- Note that if you turn on symbol splitting for backwards compatibility,
253
- Sequel will split virtual row methods with double underscores and
254
- return them as qualified identifiers:
255
-
256
- Sequel.split_symbols = true
257
- ds.where{|o| o.table__column}
258
- ds.where{table__column}
259
- WHERE table.column
260
-
261
- It's not recommended that you rely on this, it's better to convert the calls
262
- to the recommended form:
263
-
264
- ds.where{|o| o.table[:column]}
265
- ds.where{table[:column]}