File: features.rb

package info (click to toggle)
ruby-sequel 5.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,408 kB
  • sloc: ruby: 113,747; makefile: 3
file content (275 lines) | stat: -rw-r--r-- 8,404 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# frozen-string-literal: true

module Sequel
  class Dataset
    # ---------------------
    # :section: 4 - Methods that describe what the dataset supports
    # These methods all return booleans, with most describing whether or not the
    # dataset supports a feature.
    # ---------------------
    
    # Whether this dataset quotes identifiers.
    def quote_identifiers?
      @opts.fetch(:quote_identifiers, true)
    end
    
    # Whether this dataset will provide accurate number of rows matched for
    # delete and update statements, true by default.  Accurate in this case is the number of
    # rows matched by the dataset's filter.
    def provides_accurate_rows_matched?
      true
    end
    
    # Whether you must use a column alias list for recursive CTEs, false by default.
    def recursive_cte_requires_column_aliases?
      false
    end

    # Whether the dataset requires SQL standard datetimes. False by default,
    # as most allow strings with ISO 8601 format.
    def requires_sql_standard_datetimes?
      false
    end

    # Whether type specifiers are required for prepared statement/bound
    # variable argument placeholders (i.e. :bv__integer), false by default.
    def requires_placeholder_type_specifiers?
      false
    end

    # Whether the dataset supports common table expressions, false by default.
    # If given, +type+ can be :select, :insert, :update, or :delete, in which case it
    # determines whether WITH is supported for the respective statement type.
    def supports_cte?(type=:select)
      false
    end

    # Whether the dataset supports common table expressions in subqueries, false by default.
    # If false, applies the WITH clause to the main query, which can cause issues
    # if multiple WITH clauses use the same name.
    def supports_cte_in_subqueries?
      false
    end

    # Whether deleting from joined datasets is supported, false by default.
    def supports_deleting_joins?
      supports_modifying_joins?
    end
    
    # Whether the database supports derived column lists (e.g.
    # "table_expr AS table_alias(column_alias1, column_alias2, ...)"), true by
    # default.
    def supports_derived_column_lists?
      true
    end

    # Whether the dataset supports or can emulate the DISTINCT ON clause, false by default.
    def supports_distinct_on?
      false
    end

    # Whether the dataset supports CUBE with GROUP BY, false by default.
    def supports_group_cube?
      false
    end

    # Whether the dataset supports ROLLUP with GROUP BY, false by default.
    def supports_group_rollup?
      false
    end

    # Whether the dataset supports GROUPING SETS with GROUP BY, false by default.
    def supports_grouping_sets?
      false
    end

    # Whether this dataset supports the +insert_select+ method for returning all columns values
    # directly from an insert query, false by default.
    def supports_insert_select?
      supports_returning?(:insert)
    end

    # Whether the dataset supports the INTERSECT and EXCEPT compound operations, true by default.
    def supports_intersect_except?
      true
    end

    # Whether the dataset supports the INTERSECT ALL and EXCEPT ALL compound operations, true by default.
    def supports_intersect_except_all?
      true
    end

    # Whether the dataset supports the IS TRUE syntax, true by default.
    def supports_is_true?
      true
    end
    
    # Whether the dataset supports the JOIN table USING (column1, ...) syntax, true by default.
    # If false, support is emulated using JOIN table ON (table.column1 = other_table.column1).
    def supports_join_using?
      true
    end
    
    # Whether the dataset supports LATERAL for subqueries in the FROM or JOIN clauses, false by default.
    def supports_lateral_subqueries?
      false
    end

    # Whether limits are supported in correlated subqueries, true by default.
    def supports_limits_in_correlated_subqueries?
      true
    end
    
    # Whether the dataset supports skipping raising an error instead of waiting for locked rows when returning data, false by default.
    def supports_nowait?
      false
    end

    # Whether the MERGE statement is supported, false by default.
    def supports_merge?
      false
    end

    # Whether modifying joined datasets is supported, false by default.
    def supports_modifying_joins?
      false
    end
    
    # Whether the IN/NOT IN operators support multiple columns when an
    # array of values is given, true by default.
    def supports_multiple_column_in?
      true
    end

    # Whether offsets are supported in correlated subqueries, true by default.
    def supports_offsets_in_correlated_subqueries?
      true
    end

    # Whether the dataset supports or can fully emulate the DISTINCT ON clause,
    # including respecting the ORDER BY clause, false by default.
    def supports_ordered_distinct_on?
      supports_distinct_on?
    end
    
    # Whether placeholder literalizers are supported, true by default.
    def supports_placeholder_literalizer?
      true
    end

    # Whether the dataset supports pattern matching by regular expressions, false by default.
    def supports_regexp?
      false
    end

    # Whether the dataset supports REPLACE syntax, false by default.
    def supports_replace?
      false
    end

    # Whether the RETURNING clause is supported for the given type of query, false by default.
    # +type+ can be :insert, :update, or :delete.
    def supports_returning?(type)
      false
    end

    # Whether the dataset supports skipping locked rows when returning data, false by default.
    def supports_skip_locked?
      false
    end

    # Whether the database supports <tt>SELECT *, column FROM table</tt>, true by default.
    def supports_select_all_and_column?
      true
    end

    # Whether the dataset supports timezones in literal timestamps, false by default.
    def supports_timestamp_timezones?
      false
    end
    
    # Whether the dataset supports fractional seconds in literal timestamps, true by default.
    def supports_timestamp_usecs?
      true
    end
    
    # Whether updating joined datasets is supported, false by default.
    def supports_updating_joins?
      supports_modifying_joins?
    end
    
    # Whether the dataset supports the WINDOW clause to define windows used by multiple
    # window functions, false by default.
    def supports_window_clause?
      false
    end

    # Whether the dataset supports window functions, false by default.
    def supports_window_functions?
      false
    end
    
    # Whether the dataset supports the given window function option.  True by default.
    # This should only be called if supports_window_functions? is true. Possible options
    # are :rows, :range, :groups, :offset, :exclude.
    def supports_window_function_frame_option?(option)
      case option
      when :rows, :range, :offset
        true
      else
        false
      end
    end
    
    # Whether the dataset supports WHERE TRUE (or WHERE 1 for databases that
    # that use 1 for true), true by default.
    def supports_where_true?
      true
    end

    private

    # Whether insert(nil) or insert({}) must be emulated by
    # using at least one value.
    def insert_supports_empty_values?
      true
    end

    # Whether the dataset needs ESCAPE for LIKE for correct behavior.
    def requires_like_escape?
      true
    end

    # Whether ORDER BY col NULLS FIRST/LAST must be emulated.
    def requires_emulating_nulls_first?
      false
    end

    # Whether common table expressions are supported in UNION/INTERSECT/EXCEPT clauses.
    def supports_cte_in_compounds?
      supports_cte_in_subqueries?
    end

    # Whether the dataset supports the FILTER clause for aggregate functions.
    # If not, support is emulated using CASE.
    def supports_filtered_aggregates?
      false
    end

    # Whether the database supports quoting function names.
    def supports_quoted_function_names?
      false
    end

    # Whether the RETURNING clause is used for the given dataset.
    # +type+ can be :insert, :update, or :delete.
    def uses_returning?(type)
      opts[:returning] && !@opts[:sql] && supports_returning?(type)
    end
    
    # Whether the dataset uses WITH ROLLUP/CUBE instead of ROLLUP()/CUBE().
    def uses_with_rollup?
      false
    end
  end
end