sequel 5.83.1 → 5.85.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 (127) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sequel/adapters/shared/sqlite.rb +3 -1
  3. data/lib/sequel/connection_pool.rb +2 -2
  4. data/lib/sequel/database/schema_methods.rb +2 -0
  5. data/lib/sequel/dataset/actions.rb +9 -1
  6. data/lib/sequel/extensions/dataset_run.rb +41 -0
  7. data/lib/sequel/extensions/pg_json_ops.rb +642 -9
  8. data/lib/sequel/sql.rb +8 -5
  9. data/lib/sequel/version.rb +2 -2
  10. metadata +4 -237
  11. data/CHANGELOG +0 -1397
  12. data/README.rdoc +0 -936
  13. data/doc/advanced_associations.rdoc +0 -884
  14. data/doc/association_basics.rdoc +0 -1859
  15. data/doc/bin_sequel.rdoc +0 -146
  16. data/doc/cheat_sheet.rdoc +0 -255
  17. data/doc/code_order.rdoc +0 -104
  18. data/doc/core_extensions.rdoc +0 -405
  19. data/doc/dataset_basics.rdoc +0 -96
  20. data/doc/dataset_filtering.rdoc +0 -222
  21. data/doc/extensions.rdoc +0 -77
  22. data/doc/fork_safety.rdoc +0 -84
  23. data/doc/mass_assignment.rdoc +0 -98
  24. data/doc/migration.rdoc +0 -660
  25. data/doc/model_dataset_method_design.rdoc +0 -129
  26. data/doc/model_hooks.rdoc +0 -254
  27. data/doc/model_plugins.rdoc +0 -270
  28. data/doc/mssql_stored_procedures.rdoc +0 -43
  29. data/doc/object_model.rdoc +0 -563
  30. data/doc/opening_databases.rdoc +0 -439
  31. data/doc/postgresql.rdoc +0 -611
  32. data/doc/prepared_statements.rdoc +0 -144
  33. data/doc/querying.rdoc +0 -1070
  34. data/doc/reflection.rdoc +0 -120
  35. data/doc/release_notes/5.0.0.txt +0 -159
  36. data/doc/release_notes/5.1.0.txt +0 -31
  37. data/doc/release_notes/5.10.0.txt +0 -84
  38. data/doc/release_notes/5.11.0.txt +0 -83
  39. data/doc/release_notes/5.12.0.txt +0 -141
  40. data/doc/release_notes/5.13.0.txt +0 -27
  41. data/doc/release_notes/5.14.0.txt +0 -63
  42. data/doc/release_notes/5.15.0.txt +0 -39
  43. data/doc/release_notes/5.16.0.txt +0 -110
  44. data/doc/release_notes/5.17.0.txt +0 -31
  45. data/doc/release_notes/5.18.0.txt +0 -69
  46. data/doc/release_notes/5.19.0.txt +0 -28
  47. data/doc/release_notes/5.2.0.txt +0 -33
  48. data/doc/release_notes/5.20.0.txt +0 -89
  49. data/doc/release_notes/5.21.0.txt +0 -87
  50. data/doc/release_notes/5.22.0.txt +0 -48
  51. data/doc/release_notes/5.23.0.txt +0 -56
  52. data/doc/release_notes/5.24.0.txt +0 -56
  53. data/doc/release_notes/5.25.0.txt +0 -32
  54. data/doc/release_notes/5.26.0.txt +0 -35
  55. data/doc/release_notes/5.27.0.txt +0 -21
  56. data/doc/release_notes/5.28.0.txt +0 -16
  57. data/doc/release_notes/5.29.0.txt +0 -22
  58. data/doc/release_notes/5.3.0.txt +0 -121
  59. data/doc/release_notes/5.30.0.txt +0 -20
  60. data/doc/release_notes/5.31.0.txt +0 -148
  61. data/doc/release_notes/5.32.0.txt +0 -46
  62. data/doc/release_notes/5.33.0.txt +0 -24
  63. data/doc/release_notes/5.34.0.txt +0 -40
  64. data/doc/release_notes/5.35.0.txt +0 -56
  65. data/doc/release_notes/5.36.0.txt +0 -60
  66. data/doc/release_notes/5.37.0.txt +0 -30
  67. data/doc/release_notes/5.38.0.txt +0 -28
  68. data/doc/release_notes/5.39.0.txt +0 -19
  69. data/doc/release_notes/5.4.0.txt +0 -80
  70. data/doc/release_notes/5.40.0.txt +0 -40
  71. data/doc/release_notes/5.41.0.txt +0 -25
  72. data/doc/release_notes/5.42.0.txt +0 -136
  73. data/doc/release_notes/5.43.0.txt +0 -98
  74. data/doc/release_notes/5.44.0.txt +0 -32
  75. data/doc/release_notes/5.45.0.txt +0 -34
  76. data/doc/release_notes/5.46.0.txt +0 -87
  77. data/doc/release_notes/5.47.0.txt +0 -59
  78. data/doc/release_notes/5.48.0.txt +0 -14
  79. data/doc/release_notes/5.49.0.txt +0 -59
  80. data/doc/release_notes/5.5.0.txt +0 -61
  81. data/doc/release_notes/5.50.0.txt +0 -78
  82. data/doc/release_notes/5.51.0.txt +0 -47
  83. data/doc/release_notes/5.52.0.txt +0 -87
  84. data/doc/release_notes/5.53.0.txt +0 -23
  85. data/doc/release_notes/5.54.0.txt +0 -27
  86. data/doc/release_notes/5.55.0.txt +0 -21
  87. data/doc/release_notes/5.56.0.txt +0 -51
  88. data/doc/release_notes/5.57.0.txt +0 -23
  89. data/doc/release_notes/5.58.0.txt +0 -31
  90. data/doc/release_notes/5.59.0.txt +0 -73
  91. data/doc/release_notes/5.6.0.txt +0 -31
  92. data/doc/release_notes/5.60.0.txt +0 -22
  93. data/doc/release_notes/5.61.0.txt +0 -43
  94. data/doc/release_notes/5.62.0.txt +0 -132
  95. data/doc/release_notes/5.63.0.txt +0 -33
  96. data/doc/release_notes/5.64.0.txt +0 -50
  97. data/doc/release_notes/5.65.0.txt +0 -21
  98. data/doc/release_notes/5.66.0.txt +0 -24
  99. data/doc/release_notes/5.67.0.txt +0 -32
  100. data/doc/release_notes/5.68.0.txt +0 -61
  101. data/doc/release_notes/5.69.0.txt +0 -26
  102. data/doc/release_notes/5.7.0.txt +0 -108
  103. data/doc/release_notes/5.70.0.txt +0 -35
  104. data/doc/release_notes/5.71.0.txt +0 -21
  105. data/doc/release_notes/5.72.0.txt +0 -33
  106. data/doc/release_notes/5.73.0.txt +0 -66
  107. data/doc/release_notes/5.74.0.txt +0 -45
  108. data/doc/release_notes/5.75.0.txt +0 -35
  109. data/doc/release_notes/5.76.0.txt +0 -86
  110. data/doc/release_notes/5.77.0.txt +0 -63
  111. data/doc/release_notes/5.78.0.txt +0 -67
  112. data/doc/release_notes/5.79.0.txt +0 -28
  113. data/doc/release_notes/5.8.0.txt +0 -170
  114. data/doc/release_notes/5.80.0.txt +0 -40
  115. data/doc/release_notes/5.81.0.txt +0 -31
  116. data/doc/release_notes/5.82.0.txt +0 -61
  117. data/doc/release_notes/5.83.0.txt +0 -56
  118. data/doc/release_notes/5.9.0.txt +0 -99
  119. data/doc/schema_modification.rdoc +0 -679
  120. data/doc/security.rdoc +0 -443
  121. data/doc/sharding.rdoc +0 -286
  122. data/doc/sql.rdoc +0 -648
  123. data/doc/testing.rdoc +0 -204
  124. data/doc/thread_safety.rdoc +0 -15
  125. data/doc/transactions.rdoc +0 -250
  126. data/doc/validations.rdoc +0 -558
  127. 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]}