sequel 2.11.0 → 2.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +168 -0
- data/README.rdoc +77 -95
- data/Rakefile +100 -80
- data/bin/sequel +2 -1
- data/doc/advanced_associations.rdoc +23 -32
- data/doc/cheat_sheet.rdoc +23 -40
- data/doc/dataset_filtering.rdoc +6 -6
- data/doc/prepared_statements.rdoc +22 -22
- data/doc/release_notes/2.12.0.txt +534 -0
- data/doc/schema.rdoc +3 -1
- data/doc/sharding.rdoc +8 -8
- data/doc/virtual_rows.rdoc +65 -0
- data/lib/sequel.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/ado.rb +3 -3
- data/lib/{sequel_core → sequel}/adapters/db2.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/dbi.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/do.rb +9 -5
- data/lib/{sequel_core → sequel}/adapters/do/mysql.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/do/postgres.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/do/sqlite.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/firebird.rb +84 -80
- data/lib/{sequel_core → sequel}/adapters/informix.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc.rb +21 -14
- data/lib/{sequel_core → sequel}/adapters/jdbc/h2.rb +14 -13
- data/lib/{sequel_core → sequel}/adapters/jdbc/mysql.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc/oracle.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc/postgresql.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc/sqlite.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/mysql.rb +60 -39
- data/lib/{sequel_core → sequel}/adapters/odbc.rb +8 -4
- data/lib/{sequel_core → sequel}/adapters/openbase.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/oracle.rb +38 -7
- data/lib/{sequel_core → sequel}/adapters/postgres.rb +24 -24
- data/lib/{sequel_core → sequel}/adapters/shared/mssql.rb +5 -5
- data/lib/{sequel_core → sequel}/adapters/shared/mysql.rb +126 -71
- data/lib/{sequel_core → sequel}/adapters/shared/oracle.rb +7 -10
- data/lib/{sequel_core → sequel}/adapters/shared/postgres.rb +159 -125
- data/lib/{sequel_core → sequel}/adapters/shared/progress.rb +1 -2
- data/lib/{sequel_core → sequel}/adapters/shared/sqlite.rb +72 -67
- data/lib/{sequel_core → sequel}/adapters/sqlite.rb +11 -7
- data/lib/{sequel_core → sequel}/adapters/utils/date_format.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/utils/stored_procedures.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/utils/unsupported.rb +19 -0
- data/lib/{sequel_core → sequel}/connection_pool.rb +7 -5
- data/lib/sequel/core.rb +221 -0
- data/lib/{sequel_core → sequel}/core_sql.rb +91 -49
- data/lib/{sequel_core → sequel}/database.rb +264 -149
- data/lib/{sequel_core/schema/generator.rb → sequel/database/schema_generator.rb} +6 -2
- data/lib/{sequel_core/database/schema.rb → sequel/database/schema_methods.rb} +12 -12
- data/lib/sequel/database/schema_sql.rb +224 -0
- data/lib/{sequel_core → sequel}/dataset.rb +78 -236
- data/lib/{sequel_core → sequel}/dataset/convenience.rb +99 -61
- data/lib/{sequel_core/object_graph.rb → sequel/dataset/graph.rb} +16 -14
- data/lib/{sequel_core → sequel}/dataset/prepared_statements.rb +1 -1
- data/lib/{sequel_core → sequel}/dataset/sql.rb +150 -99
- data/lib/sequel/deprecated.rb +593 -0
- data/lib/sequel/deprecated_migration.rb +91 -0
- data/lib/sequel/exceptions.rb +48 -0
- data/lib/sequel/extensions/blank.rb +42 -0
- data/lib/{sequel_model → sequel/extensions}/inflector.rb +8 -1
- data/lib/{sequel_core → sequel/extensions}/migration.rb +1 -1
- data/lib/{sequel_core/dataset → sequel/extensions}/pagination.rb +0 -0
- data/lib/{sequel_core → sequel/extensions}/pretty_table.rb +7 -0
- data/lib/{sequel_core/dataset → sequel/extensions}/query.rb +7 -0
- data/lib/sequel/extensions/string_date_time.rb +47 -0
- data/lib/sequel/metaprogramming.rb +43 -0
- data/lib/sequel/model.rb +110 -0
- data/lib/sequel/model/associations.rb +1300 -0
- data/lib/sequel/model/base.rb +937 -0
- data/lib/sequel/model/deprecated.rb +204 -0
- data/lib/sequel/model/deprecated_hooks.rb +103 -0
- data/lib/sequel/model/deprecated_inflector.rb +335 -0
- data/lib/sequel/model/deprecated_validations.rb +388 -0
- data/lib/sequel/model/errors.rb +39 -0
- data/lib/{sequel_model → sequel/model}/exceptions.rb +4 -4
- data/lib/sequel/model/inflections.rb +208 -0
- data/lib/sequel/model/plugins.rb +76 -0
- data/lib/sequel/plugins/caching.rb +122 -0
- data/lib/sequel/plugins/hook_class_methods.rb +122 -0
- data/lib/sequel/plugins/schema.rb +53 -0
- data/lib/sequel/plugins/serialization.rb +117 -0
- data/lib/sequel/plugins/single_table_inheritance.rb +63 -0
- data/lib/sequel/plugins/validation_class_methods.rb +384 -0
- data/lib/sequel/plugins/validation_helpers.rb +150 -0
- data/lib/{sequel_core → sequel}/sql.rb +125 -190
- data/lib/{sequel_core → sequel}/version.rb +2 -1
- data/lib/sequel_core.rb +1 -172
- data/lib/sequel_model.rb +1 -91
- data/spec/adapters/firebird_spec.rb +5 -5
- data/spec/adapters/informix_spec.rb +1 -1
- data/spec/adapters/mysql_spec.rb +128 -42
- data/spec/adapters/oracle_spec.rb +47 -19
- data/spec/adapters/postgres_spec.rb +64 -52
- data/spec/adapters/spec_helper.rb +1 -1
- data/spec/adapters/sqlite_spec.rb +12 -17
- data/spec/{sequel_core → core}/connection_pool_spec.rb +10 -10
- data/spec/{sequel_core → core}/core_ext_spec.rb +19 -19
- data/spec/{sequel_core → core}/core_sql_spec.rb +68 -71
- data/spec/{sequel_core → core}/database_spec.rb +135 -99
- data/spec/{sequel_core → core}/dataset_spec.rb +398 -242
- data/spec/{sequel_core → core}/expression_filters_spec.rb +13 -13
- data/spec/core/migration_spec.rb +263 -0
- data/spec/{sequel_core → core}/object_graph_spec.rb +10 -10
- data/spec/{sequel_core → core}/pretty_table_spec.rb +2 -2
- data/spec/{sequel_core → core}/schema_generator_spec.rb +0 -0
- data/spec/{sequel_core → core}/schema_spec.rb +8 -10
- data/spec/{sequel_core → core}/spec_helper.rb +29 -2
- data/spec/{sequel_core → core}/version_spec.rb +0 -0
- data/spec/extensions/blank_spec.rb +67 -0
- data/spec/extensions/caching_spec.rb +201 -0
- data/spec/{sequel_model/hooks_spec.rb → extensions/hook_class_methods_spec.rb} +8 -23
- data/spec/{sequel_model → extensions}/inflector_spec.rb +3 -0
- data/spec/{sequel_core → extensions}/migration_spec.rb +4 -4
- data/spec/extensions/pagination_spec.rb +99 -0
- data/spec/extensions/pretty_table_spec.rb +91 -0
- data/spec/extensions/query_spec.rb +85 -0
- data/spec/{sequel_model → extensions}/schema_spec.rb +22 -1
- data/spec/extensions/serialization_spec.rb +109 -0
- data/spec/extensions/single_table_inheritance_spec.rb +53 -0
- data/spec/{sequel_model → extensions}/spec_helper.rb +13 -4
- data/spec/extensions/string_date_time_spec.rb +93 -0
- data/spec/{sequel_model/validations_spec.rb → extensions/validation_class_methods_spec.rb} +15 -103
- data/spec/extensions/validation_helpers_spec.rb +291 -0
- data/spec/integration/dataset_test.rb +31 -0
- data/spec/integration/eager_loader_test.rb +17 -30
- data/spec/integration/schema_test.rb +8 -5
- data/spec/integration/spec_helper.rb +17 -0
- data/spec/integration/transaction_test.rb +68 -0
- data/spec/{sequel_model → model}/association_reflection_spec.rb +0 -0
- data/spec/{sequel_model → model}/associations_spec.rb +23 -10
- data/spec/{sequel_model → model}/base_spec.rb +29 -20
- data/spec/{sequel_model → model}/caching_spec.rb +16 -14
- data/spec/{sequel_model → model}/dataset_methods_spec.rb +0 -0
- data/spec/{sequel_model → model}/eager_loading_spec.rb +8 -8
- data/spec/model/hooks_spec.rb +472 -0
- data/spec/model/inflector_spec.rb +126 -0
- data/spec/{sequel_model → model}/model_spec.rb +25 -20
- data/spec/model/plugins_spec.rb +142 -0
- data/spec/{sequel_model → model}/record_spec.rb +121 -62
- data/spec/model/schema_spec.rb +92 -0
- data/spec/model/spec_helper.rb +124 -0
- data/spec/model/validations_spec.rb +1080 -0
- metadata +136 -107
- data/lib/sequel_core/core_ext.rb +0 -217
- data/lib/sequel_core/dataset/callback.rb +0 -13
- data/lib/sequel_core/dataset/schema.rb +0 -15
- data/lib/sequel_core/deprecated.rb +0 -26
- data/lib/sequel_core/exceptions.rb +0 -44
- data/lib/sequel_core/schema.rb +0 -2
- data/lib/sequel_core/schema/sql.rb +0 -325
- data/lib/sequel_model/association_reflection.rb +0 -267
- data/lib/sequel_model/associations.rb +0 -499
- data/lib/sequel_model/base.rb +0 -539
- data/lib/sequel_model/caching.rb +0 -82
- data/lib/sequel_model/dataset_methods.rb +0 -26
- data/lib/sequel_model/eager_loading.rb +0 -370
- data/lib/sequel_model/hooks.rb +0 -101
- data/lib/sequel_model/plugins.rb +0 -62
- data/lib/sequel_model/record.rb +0 -568
- data/lib/sequel_model/schema.rb +0 -49
- data/lib/sequel_model/validations.rb +0 -429
- data/spec/sequel_model/plugins_spec.rb +0 -80
@@ -0,0 +1,593 @@
|
|
1
|
+
%w'bigdecimal/util enumerator yaml'.each do |f|
|
2
|
+
require f
|
3
|
+
end
|
4
|
+
|
5
|
+
module Sequel
|
6
|
+
# This module makes it easy to print deprecation warnings with optional backtraces to a given stream.
|
7
|
+
# There are a couple of methods you can use to change where the deprecation methods are printed
|
8
|
+
# and whether they should include backtraces:
|
9
|
+
#
|
10
|
+
# Sequel::Deprecation.output = $stderr # print deprecation messages to standard error (default)
|
11
|
+
# Sequel::Deprecation.output = File.open('deprecated_calls.txt', 'wb') # use a file instead
|
12
|
+
# Sequel::Deprecation.backtraces = false # don't include backtraces
|
13
|
+
# Sequel::Deprecation.backtraces = true # include full backtraces
|
14
|
+
# Sequel::Deprecation.backtraces = 10 # include 10 backtrace lines (default)
|
15
|
+
# Sequel::Deprecation.backtraces = 1 # include 1 backtrace line
|
16
|
+
module Deprecation
|
17
|
+
extend Metaprogramming
|
18
|
+
|
19
|
+
@output = $stderr
|
20
|
+
@backtraces = 10
|
21
|
+
|
22
|
+
metaattr_accessor :output, :backtraces
|
23
|
+
|
24
|
+
# Print the message to the output stream
|
25
|
+
def self.deprecate(method, instead=nil)
|
26
|
+
message = instead ? "#{method} is deprecated and will be removed in Sequel 3.0. #{instead}." : method
|
27
|
+
return unless output
|
28
|
+
output.puts(message)
|
29
|
+
case backtraces
|
30
|
+
when Integer
|
31
|
+
b = backtraces
|
32
|
+
caller.each do |c|
|
33
|
+
b -= 1
|
34
|
+
output.puts(c)
|
35
|
+
break if b == 0
|
36
|
+
end
|
37
|
+
when true
|
38
|
+
caller.each{|c| output.puts(c)}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
require 'deprecated_migration'
|
44
|
+
|
45
|
+
def self.open(*args, &block)
|
46
|
+
Deprecation.deprecate('Sequel.open', 'Use Sequel.connect')
|
47
|
+
Database.connect(*args, &block)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.upcase_identifiers=(value)
|
51
|
+
Deprecation.deprecate('Sequel.upcase_identifiers=', 'Use Sequel.identifier_input_method = :upcase or nil')
|
52
|
+
Database.identifier_input_method = value ? :upcase : nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.use_parse_tree
|
56
|
+
Deprecation.deprecate('Sequel.use_parse_tree', 'Sequel has not used ParseTree since 2.2')
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.use_parse_tree=(val)
|
61
|
+
Deprecation.deprecate('Sequel.use_parse_tree=', 'Sequel has not used ParseTree since 2.2')
|
62
|
+
raise(Error, 'ParseTree support has been removed from Sequel') if val
|
63
|
+
end
|
64
|
+
|
65
|
+
class Database
|
66
|
+
def self.upcase_identifiers=(value)
|
67
|
+
Deprecation.deprecate('Sequel::Database.upcase_identifiers=', 'Use Sequel::Database.identifier_input_method = :upcase or nil')
|
68
|
+
self.identifier_input_method = value ? :upcase : nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def upcase_identifiers=(v)
|
72
|
+
Deprecation.deprecate('Sequel::Database#upcase_identifiers=', 'Use Sequel::Database#identifier_input_method = :upcase or nil')
|
73
|
+
self.identifier_input_method = v ? :upcase : nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def upcase_identifiers?
|
77
|
+
Deprecation.deprecate('Sequel::Database#upcase_identifiers?', 'Use Sequel::Database#identifier_input_method == :upcase')
|
78
|
+
identifier_input_method == :upcase
|
79
|
+
end
|
80
|
+
|
81
|
+
def >>(*args, &block)
|
82
|
+
Deprecation.deprecate('Sequel::Database#>>', 'Use Sequel::Database#fetch')
|
83
|
+
fetch(*args, &block)
|
84
|
+
end
|
85
|
+
|
86
|
+
def query(&block)
|
87
|
+
Deprecation.deprecate('Sequel::Database#query', 'require "sequel/extensions/query" first')
|
88
|
+
dataset.query(&block)
|
89
|
+
end
|
90
|
+
|
91
|
+
def logger
|
92
|
+
Deprecation.deprecate('Sequel::Database#logger', 'Use Sequel::Database#loggers')
|
93
|
+
@loggers.first
|
94
|
+
end
|
95
|
+
|
96
|
+
def multi_threaded?
|
97
|
+
Deprecation.deprecate('Sequel::Database#multi_threaded?', 'Use !database.single_threaded?')
|
98
|
+
!@single_threaded
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class Dataset
|
103
|
+
DATASET_CLASSES = []
|
104
|
+
STOCK_TRANSFORMS = {
|
105
|
+
:marshal => [
|
106
|
+
# for backwards-compatibility we support also non-base64-encoded values.
|
107
|
+
proc {|v| Marshal.load(v.unpack('m')[0]) rescue Marshal.load(v)},
|
108
|
+
proc {|v| [Marshal.dump(v)].pack('m')}
|
109
|
+
],
|
110
|
+
:yaml => [
|
111
|
+
proc {|v| YAML.load v if v},
|
112
|
+
proc {|v| v.to_yaml}
|
113
|
+
]
|
114
|
+
}
|
115
|
+
|
116
|
+
def self.dataset_classes
|
117
|
+
Deprecation.deprecate('Sequel::Dataset#dataset_classes', 'No replacement is planned')
|
118
|
+
DATASET_CLASSES
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.inherited(c)
|
122
|
+
DATASET_CLASSES << c
|
123
|
+
end
|
124
|
+
|
125
|
+
def upcase_identifiers=(v)
|
126
|
+
Deprecation.deprecate('Sequel::Dataset#upcase_identifiers=', 'Use Sequel::Dataset#identifier_input_method = :upcase or nil')
|
127
|
+
@identifier_input_method = v ? :upcase : nil
|
128
|
+
end
|
129
|
+
|
130
|
+
def upcase_identifiers?
|
131
|
+
Deprecation.deprecate('Sequel::Dataset#upcase_identifiers?', 'Use Sequel::Dataset#identifier_input_method == :upcase')
|
132
|
+
@identifier_input_method == :upcase
|
133
|
+
end
|
134
|
+
|
135
|
+
def model_classes
|
136
|
+
Deprecation.deprecate('Sequel::Dataset#model_classes', 'Sequel::Model datasets no longer set this information')
|
137
|
+
@opts[:models]
|
138
|
+
end
|
139
|
+
|
140
|
+
def polymorphic_key
|
141
|
+
Deprecation.deprecate('Sequel::Dataset#polymorphic_key', 'Sequel::Model datasets no longer set this information')
|
142
|
+
@opts[:polymorphic_key]
|
143
|
+
end
|
144
|
+
|
145
|
+
def set_model(key, *args)
|
146
|
+
Deprecation.deprecate('Sequel::Dataset#set_model', 'Use Sequel::Dataset#set_row_proc with an appropriate row proc')
|
147
|
+
# This code is more verbose then necessary for performance reasons
|
148
|
+
case key
|
149
|
+
when nil # set_model(nil) => no argument provided, so the dataset is denuded
|
150
|
+
@opts.merge!(:naked => true, :models => nil, :polymorphic_key => nil)
|
151
|
+
self.row_proc = nil
|
152
|
+
when Class
|
153
|
+
# isomorphic model
|
154
|
+
@opts.merge!(:naked => nil, :models => {nil => key}, :polymorphic_key => nil)
|
155
|
+
if key.respond_to?(:load)
|
156
|
+
# the class has a values setter method, so we use it
|
157
|
+
self.row_proc = proc{|h| key.load(h, *args)}
|
158
|
+
else
|
159
|
+
# otherwise we just pass the hash to the constructor
|
160
|
+
self.row_proc = proc{|h| key.new(h, *args)}
|
161
|
+
end
|
162
|
+
when Symbol
|
163
|
+
# polymorphic model
|
164
|
+
hash = args.shift || raise(ArgumentError, "No class hash supplied for polymorphic model")
|
165
|
+
@opts.merge!(:naked => true, :models => hash, :polymorphic_key => key)
|
166
|
+
if (hash.empty? ? (hash[nil] rescue nil) : hash.values.first).respond_to?(:load)
|
167
|
+
# the class has a values setter method, so we use it
|
168
|
+
self.row_proc = proc do |h|
|
169
|
+
c = hash[h[key]] || hash[nil] || \
|
170
|
+
raise(Error, "No matching model class for record (#{polymorphic_key} => #{h[polymorphic_key].inspect})")
|
171
|
+
c.load(h, *args)
|
172
|
+
end
|
173
|
+
else
|
174
|
+
# otherwise we just pass the hash to the constructor
|
175
|
+
self.row_proc = proc do |h|
|
176
|
+
c = hash[h[key]] || hash[nil] || \
|
177
|
+
raise(Error, "No matching model class for record (#{polymorphic_key} => #{h[polymorphic_key].inspect})")
|
178
|
+
c.new(h, *args)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
else
|
182
|
+
raise ArgumentError, "Invalid model specified"
|
183
|
+
end
|
184
|
+
self
|
185
|
+
end
|
186
|
+
|
187
|
+
def create_view(name)
|
188
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#create_view', 'Use Sequel::Database#create_view')
|
189
|
+
@db.create_view(name, self)
|
190
|
+
end
|
191
|
+
|
192
|
+
def create_or_replace_view(name)
|
193
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#create_or_replace_view', 'Use Sequel::Database#create_or_replace_view')
|
194
|
+
@db.create_or_replace_view(name, self)
|
195
|
+
end
|
196
|
+
|
197
|
+
def size
|
198
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#size', 'Use Sequel::Dataset#count')
|
199
|
+
count
|
200
|
+
end
|
201
|
+
|
202
|
+
def uniq(*args)
|
203
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#uniq', 'Use Sequel::Dataset#distinct')
|
204
|
+
distinct(*args)
|
205
|
+
end
|
206
|
+
|
207
|
+
def quote_column_ref(name)
|
208
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#quote_column_ref', 'Use Sequel::Dataset#quote_identifier')
|
209
|
+
quote_identifier(name)
|
210
|
+
end
|
211
|
+
|
212
|
+
def symbol_to_column_ref(sym)
|
213
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#symbol_to_column_ref', 'Use Sequel::Dataset#literal')
|
214
|
+
literal_symbol(sym)
|
215
|
+
end
|
216
|
+
|
217
|
+
def paginate(page_no, page_size, record_count=nil)
|
218
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#paginate', 'require "sequel/extensions/pagination" first')
|
219
|
+
require "sequel/extensions/pagination"
|
220
|
+
raise(Error, "You cannot paginate a dataset that already has a limit") if @opts[:limit]
|
221
|
+
paginated = limit(page_size, (page_no - 1) * page_size)
|
222
|
+
paginated.extend(Pagination)
|
223
|
+
paginated.set_pagination_info(page_no, page_size, record_count || count)
|
224
|
+
end
|
225
|
+
|
226
|
+
def each_page(page_size, &block)
|
227
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#each_page', 'require "sequel/extensions/pagination" first')
|
228
|
+
raise(Error, "You cannot paginate a dataset that already has a limit") if @opts[:limit]
|
229
|
+
record_count = count
|
230
|
+
total_pages = (record_count / page_size.to_f).ceil
|
231
|
+
(1..total_pages).each{|page_no| yield paginate(page_no, page_size, record_count)}
|
232
|
+
self
|
233
|
+
end
|
234
|
+
|
235
|
+
def query(&block)
|
236
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#each_page', 'require "sequel/extensions/query" first')
|
237
|
+
require "sequel/extensions/query"
|
238
|
+
copy = clone({})
|
239
|
+
copy.extend(QueryBlockCopy)
|
240
|
+
copy.instance_eval(&block)
|
241
|
+
clone(copy.opts)
|
242
|
+
end
|
243
|
+
|
244
|
+
def print(*cols)
|
245
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#print', 'require "sequel/extensions/pretty_table" first')
|
246
|
+
Sequel::PrettyTable.print(naked.all, cols.empty? ? columns : cols)
|
247
|
+
end
|
248
|
+
|
249
|
+
def transform(t)
|
250
|
+
Sequel::Deprecation.deprecate('Sequel::Dataset#transform', 'There is no replacement.')
|
251
|
+
@transform = t
|
252
|
+
t.each do |k, v|
|
253
|
+
case v
|
254
|
+
when Array
|
255
|
+
if (v.size != 2) || !v.first.is_a?(Proc) && !v.last.is_a?(Proc)
|
256
|
+
raise Error::InvalidTransform, "Invalid transform specified"
|
257
|
+
end
|
258
|
+
else
|
259
|
+
unless v = STOCK_TRANSFORMS[v]
|
260
|
+
raise Error::InvalidTransform, "Invalid transform specified"
|
261
|
+
else
|
262
|
+
t[k] = v
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
self
|
267
|
+
end
|
268
|
+
|
269
|
+
def transform_load(r)
|
270
|
+
r.inject({}) do |m, kv|
|
271
|
+
k, v = *kv
|
272
|
+
m[k] = (tt = @transform[k]) ? tt[0][v] : v
|
273
|
+
m
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
def transform_save(r)
|
278
|
+
r.inject({}) do |m, kv|
|
279
|
+
k, v = *kv
|
280
|
+
m[k] = (tt = @transform[k]) ? tt[1][v] : v
|
281
|
+
m
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
module SQL
|
287
|
+
module CastMethods
|
288
|
+
def cast_as(sql_type)
|
289
|
+
Sequel::Deprecation.deprecate('Sequel::SQL::CastMethods#cast_as', 'Use Sequel::SQL::CastMethods#cast')
|
290
|
+
cast(sql_type)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
class Blob
|
295
|
+
def to_blob(*args)
|
296
|
+
Sequel::Deprecation.deprecate('Sequel::SQL::Blob#to_blob', 'Use Sequel::SQL::Blob#to_sequel_blob')
|
297
|
+
to_sequel_blob(*args)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
module PrettyTable
|
303
|
+
def self.print(*args)
|
304
|
+
Sequel::Deprecation.deprecate('Sequel::PrettyTable#print', 'require "sequel/extensions/pretty_table" first')
|
305
|
+
require "sequel/extensions/pretty_table"
|
306
|
+
print(*args)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
class Error
|
311
|
+
class InvalidStatement < Error; end
|
312
|
+
class InvalidTransform < Error; end
|
313
|
+
class NoExistingFilter < InvalidOperation; end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
if RUBY_VERSION < '1.9.0'
|
318
|
+
class Hash
|
319
|
+
unless method_defined?(:key)
|
320
|
+
include(Module.new do
|
321
|
+
def key(*args, &block)
|
322
|
+
Sequel::Deprecation.deprecate('Hash#key', 'Use Hash#index')
|
323
|
+
index(*args, &block)
|
324
|
+
end
|
325
|
+
end)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
module Enumerable
|
331
|
+
unless method_defined?(:send_each)
|
332
|
+
def send_each(sym, *args)
|
333
|
+
Sequel::Deprecation.deprecate('Enumerable#send_each', 'Use Enumerable#each{|x| x.send(...)}')
|
334
|
+
each{|i| i.send(sym, *args)}
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
class Range
|
340
|
+
unless method_defined?(:interval)
|
341
|
+
include(Module.new do
|
342
|
+
def interval
|
343
|
+
Sequel::Deprecation.deprecate('Range#interval', 'Use range.first - range.last - (range.exclude_end? ? 1 : 0)')
|
344
|
+
last - first - (exclude_end? ? 1 : 0)
|
345
|
+
end
|
346
|
+
end)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
class Array
|
351
|
+
unless method_defined?(:extract_options!)
|
352
|
+
include(Module.new do
|
353
|
+
def extract_options!
|
354
|
+
Sequel::Deprecation.deprecate('Array#extract_options!', 'Use array.last.is_a?(Hash) ? array.pop : {}')
|
355
|
+
last.is_a?(Hash) ? pop : {}
|
356
|
+
end
|
357
|
+
end)
|
358
|
+
end
|
359
|
+
|
360
|
+
def to_sql
|
361
|
+
Sequel::Deprecation.deprecate('Array#to_sql', 'It may be a good idea to refactor your implementation so this type of method is not required')
|
362
|
+
map {|l| ((m = /^(.*)--/.match(l)) ? m[1] : l).chomp}.join(' '). \
|
363
|
+
gsub(/\/\*.*\*\//, '').gsub(/\s+/, ' ').strip
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
class String
|
368
|
+
include(Module.new do
|
369
|
+
def split_sql
|
370
|
+
Sequel::Deprecation.deprecate('String#split_sql', 'It may be a good idea to refactor your implementation so this type of method is not required')
|
371
|
+
to_sql.split(';').map {|s| s.strip}
|
372
|
+
end
|
373
|
+
|
374
|
+
def to_sql
|
375
|
+
Sequel::Deprecation.deprecate('String#to_sql', 'It may be a good idea to refactor your implementation so this type of method is not required')
|
376
|
+
split("\n").to_sql
|
377
|
+
end
|
378
|
+
|
379
|
+
def expr(*args)
|
380
|
+
Sequel::Deprecation.deprecate('String#expr', 'Use String#lit')
|
381
|
+
lit(*args)
|
382
|
+
end
|
383
|
+
|
384
|
+
unless String.method_defined?(:to_blob)
|
385
|
+
def to_blob(*args)
|
386
|
+
Sequel::Deprecation.deprecate('String#to_blob', 'Use String#to_sequel_blob')
|
387
|
+
to_sequel_blob(*args)
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
unless String.method_defined?(:blank?)
|
392
|
+
def blank?
|
393
|
+
Sequel::Deprecation.deprecate('String#blank?', "require 'sequel/extensions/blank' first")
|
394
|
+
strip.empty?
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
unless String.method_defined?(:to_date)
|
399
|
+
def to_date
|
400
|
+
Sequel::Deprecation.deprecate('String#to_date', 'You should require "sequel/extensions/string_date_time"')
|
401
|
+
begin
|
402
|
+
Date.parse(self, Sequel.convert_two_digit_years)
|
403
|
+
rescue => e
|
404
|
+
raise Sequel::Error::InvalidValue, "Invalid Date value '#{self}' (#{e.message})"
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
unless String.method_defined?(:to_datetime)
|
410
|
+
def to_datetime
|
411
|
+
Sequel::Deprecation.deprecate('String#to_datetime', 'You should require "sequel/extensions/string_date_time"')
|
412
|
+
begin
|
413
|
+
DateTime.parse(self, Sequel.convert_two_digit_years)
|
414
|
+
rescue => e
|
415
|
+
raise Sequel::Error::InvalidValue, "Invalid DateTime value '#{self}' (#{e.message})"
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
unless String.method_defined?(:to_sequel_time)
|
421
|
+
def to_sequel_time
|
422
|
+
Sequel::Deprecation.deprecate('String#to_sequel_time', 'You should require "sequel/extensions/string_date_time"')
|
423
|
+
begin
|
424
|
+
if Sequel.datetime_class == DateTime
|
425
|
+
DateTime.parse(self, Sequel.convert_two_digit_years)
|
426
|
+
else
|
427
|
+
Sequel.datetime_class.parse(self)
|
428
|
+
end
|
429
|
+
rescue => e
|
430
|
+
raise Sequel::Error::InvalidValue, "Invalid #{Sequel.datetime_class} value '#{self}' (#{e.message})"
|
431
|
+
end
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
unless String.method_defined?(:to_time)
|
436
|
+
def to_time
|
437
|
+
Sequel::Deprecation.deprecate('String#to_time', 'You should require "sequel/extensions/string_date_time"')
|
438
|
+
begin
|
439
|
+
Time.parse(self)
|
440
|
+
rescue => e
|
441
|
+
raise Sequel::Error::InvalidValue, "Invalid Time value '#{self}' (#{e.message})"
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end)
|
446
|
+
end
|
447
|
+
|
448
|
+
class Symbol
|
449
|
+
def |(sub)
|
450
|
+
return super unless (Integer === sub) || ((Array === sub) && sub.any?{|x| Integer === x})
|
451
|
+
Sequel::Deprecation.deprecate('The use of Symbol#| for SQL array subscripts', 'Use Symbol#sql_subscript')
|
452
|
+
Sequel::SQL::Subscript.new(self, Array(sub))
|
453
|
+
end
|
454
|
+
|
455
|
+
def to_column_ref(ds)
|
456
|
+
Sequel::Deprecation.deprecate('Symbol#to_column_ref', 'Use Dataset#literal')
|
457
|
+
ds.literal(self)
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
class Module
|
462
|
+
include(Module.new do
|
463
|
+
unless Module.method_defined?(:class_def)
|
464
|
+
def class_def(name, &block)
|
465
|
+
Sequel::Deprecation.deprecate('Object#class_def', "Install the metaid gem")
|
466
|
+
class_eval{define_method(name, &block)}
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
private
|
471
|
+
|
472
|
+
unless Module.method_defined?(:class_attr_overridable)
|
473
|
+
def class_attr_overridable(*meths)
|
474
|
+
Sequel::Deprecation.deprecate('Module#class_attr_overridable', "Copy the method from #{__FILE__} (line #{__LINE__}) if you need it")
|
475
|
+
meths.each{|meth| class_eval("def #{meth}; !defined?(@#{meth}) ? (@#{meth} = self.class.#{meth}) : @#{meth} end")}
|
476
|
+
attr_writer(*meths)
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
unless Module.method_defined?(:class_attr_reader)
|
481
|
+
def class_attr_reader(*meths)
|
482
|
+
Sequel::Deprecation.deprecate('Module#class_attr_reader', "Copy the method from #{__FILE__} (line #{__LINE__}) if you need it")
|
483
|
+
meths.each{|meth| define_method(meth){self.class.send(meth)}}
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
unless Module.method_defined?(:metaalias)
|
488
|
+
def metaalias(to, from)
|
489
|
+
Sequel::Deprecation.deprecate('Module#metaalias', "Copy the method from #{__FILE__} (line #{__LINE__}) if you need it")
|
490
|
+
meta_eval{alias_method to, from}
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
unless Module.method_defined?(:metaattr_accessor)
|
495
|
+
def metaattr_accessor(*meths)
|
496
|
+
Sequel::Deprecation.deprecate('Module#metaattr_accessor', "Copy the method from #{__FILE__} (line #{__LINE__}) if you need it")
|
497
|
+
meta_eval{attr_accessor(*meths)}
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
unless Module.method_defined?(:metaattr_reader)
|
502
|
+
def metaattr_reader(*meths)
|
503
|
+
Sequel::Deprecation.deprecate('Module#metaattr_reader', "Copy the method from #{__FILE__} (line #{__LINE__}) if you need it")
|
504
|
+
meta_eval{attr_reader(*meths)}
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end)
|
508
|
+
end
|
509
|
+
|
510
|
+
class FalseClass
|
511
|
+
unless method_defined?(:blank?)
|
512
|
+
include(Module.new do
|
513
|
+
def blank?
|
514
|
+
Sequel::Deprecation.deprecate('FalseClass#blank?', "require 'sequel/extensions/blank' first")
|
515
|
+
true
|
516
|
+
end
|
517
|
+
end)
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
class NilClass
|
522
|
+
unless method_defined?(:blank?)
|
523
|
+
include(Module.new do
|
524
|
+
def blank?
|
525
|
+
Sequel::Deprecation.deprecate('NilClass#blank?', "require 'sequel/extensions/blank' first")
|
526
|
+
true
|
527
|
+
end
|
528
|
+
end)
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
class Numeric
|
533
|
+
unless method_defined?(:blank?)
|
534
|
+
include(Module.new do
|
535
|
+
def blank?
|
536
|
+
Sequel::Deprecation.deprecate('Numeric#blank?', "require 'sequel/extensions/blank' first")
|
537
|
+
false
|
538
|
+
end
|
539
|
+
end)
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
class TrueClass
|
544
|
+
unless method_defined?(:blank?)
|
545
|
+
include(Module.new do
|
546
|
+
def blank?
|
547
|
+
Sequel::Deprecation.deprecate('FalseClass#blank?', "require 'sequel/extensions/blank' first")
|
548
|
+
false
|
549
|
+
end
|
550
|
+
end)
|
551
|
+
end
|
552
|
+
end
|
553
|
+
|
554
|
+
class Object
|
555
|
+
include(Module.new do
|
556
|
+
unless Object.method_defined?(:blank?)
|
557
|
+
def blank?
|
558
|
+
Sequel::Deprecation.deprecate('FalseClass#blank?', "require 'sequel/extensions/blank' first")
|
559
|
+
respond_to?(:empty?) && empty?
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
unless Object.method_defined?(:is_one_of?)
|
564
|
+
def is_one_of?(*classes)
|
565
|
+
Sequel::Deprecation.deprecate('Object#is_one_of?', "Use classes.any?{|c| object.is_a?(c)}")
|
566
|
+
classes.any?{|c| is_a?(c)}
|
567
|
+
end
|
568
|
+
end
|
569
|
+
|
570
|
+
unless Object.method_defined?(:meta_def)
|
571
|
+
def meta_def(name, &block)
|
572
|
+
Sequel::Deprecation.deprecate('Object#meta_def', "Install the metaid gem")
|
573
|
+
meta_eval{define_method(name, &block)}
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
577
|
+
unless Object.method_defined?(:meta_eval)
|
578
|
+
def meta_eval(&block)
|
579
|
+
Sequel::Deprecation.deprecate('Object#meta_eval', "Install the metaid gem")
|
580
|
+
metaclass.instance_eval(&block)
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
unless Object.method_defined?(:metaclass)
|
585
|
+
def metaclass
|
586
|
+
Sequel::Deprecation.deprecate('Object#metaclass', "Install the metaid gem")
|
587
|
+
class << self
|
588
|
+
self
|
589
|
+
end
|
590
|
+
end
|
591
|
+
end
|
592
|
+
end)
|
593
|
+
end
|