sequel 5.16.0 → 5.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50240675066a0bd3e480a52ba3ff556b962ae3d8403fb22ee210272f2fffb023
4
- data.tar.gz: d1c86ff37811732211b00b251c49bf7c4929ca7b18bf7c6ffeda1b8d0335482f
3
+ metadata.gz: 6ba219a366f7927beb723a4440c7d497d62b9a2d3b066c44ea5368253a668698
4
+ data.tar.gz: 570fde96f4cce21da26853210b29eef64e1c6adbf911d085faf5ebf907b0f013
5
5
  SHA512:
6
- metadata.gz: 6a5a5b35a91ff83c6a0dab3e5cb88e26d79dced018f46fa78ad8be2b4da37c602adba56f849c0591c12f976006ea6e511bb3153478e70f3824ac940772f14de6
7
- data.tar.gz: 50f5217691ec39036999623ce8d791fc93c270876d857e30b53892def7d36e0f3c99a3c69b13f97162f45b49dd066f1a5fcbf8b9660f96a1cd5c0c5a23c9ee72
6
+ metadata.gz: dd6070cf9080a359fd506a5ea8a9d1aaedb2a293c0ed4a123795a55a76e3e9b6ae9720da2f03ec5d1f904258a6fb12c462a2bd661a8ff79c5d0fbd27488664cd
7
+ data.tar.gz: 402bade89fccfe94c5f29a9a7767fe7cca1bd0549e37fe8591268507b8025365b2ff7af7ef36dfa6a281607d44f4d6fb683dbff801d55003c546981bca1b932d
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ === 5.17.0 (2019-02-01)
2
+
3
+ * Support skip_auto_validations instance method in auto_validations plugin (oldgreen, jeremyevans) (#1592)
4
+
5
+ * Support :preconnect_extensions Database option for loading extensions before :preconnect option (jeremyevans)
6
+
7
+ * Avoid usage of Proc.new with implicit block as ruby 2.7+ deprecates this behavior (jeremyevans)
8
+
9
+ * Allow Sequel[].as to be used for constructing aliases with eager_graph (e.g. Model.eager_graph(Sequel[:a].as(:b))) (jeremyevans) (#1588)
10
+
1
11
  === 5.16.0 (2019-01-02)
2
12
 
3
13
  * Convert integer columns to bigint columns when copying SQLite databases to other databases using bin/sequel -C (jeremyevans) (#1584)
@@ -75,14 +75,23 @@ These options are shared by all adapters unless otherwise noted.
75
75
 
76
76
  :adapter :: The adapter to use
77
77
  :database :: The name of the database to which to connect
78
+ :extensions :: Extensions to load into this Database instance. Can be a symbol, array of symbols,
79
+ or string with extensions separated by columns. These extensions are loaded after
80
+ connections are made by the :preconnect option.
78
81
  :cache_schema :: Whether schema should be cached for this database (true by default)
79
82
  :default_string_column_size :: The default size for string columns (255 by default)
80
83
  :host :: The hostname of the database server to which to connect
81
84
  :keep_reference :: Whether to keep a reference to the database in Sequel::DATABASES (true by default)
85
+ :logger :: A specific SQL logger to log to
82
86
  :loggers :: An array of SQL loggers to log to
83
87
  :log_connection_info :: Whether to include connection information in log messages (false by default)
84
88
  :log_warn_duration :: The amount of seconds after which the queries are logged at :warn level
85
89
  :password :: The password for the user account
90
+ :preconnect :: Whether to automatically make the maximum number of connections when setting up the pool.
91
+ Can be set to "concurrently" to connect in parallel.
92
+ :preconnect_extensions :: Similar to the :extensions option, but loads the extensions before the
93
+ connections are made by the :preconnect option.
94
+ :quote_identifiers :: Whether to quote identifiers.
86
95
  :servers :: A hash with symbol keys and hash or proc values, used with primary/replica and sharded database configurations
87
96
  :sql_log_level :: The level at which to issue queries to the loggers (:info by default)
88
97
  :test :: Whether to test that a valid database connection can be made (true by default)
@@ -95,8 +104,6 @@ The following options can be specified and are passed to the database's internal
95
104
  useful for customizations that you want to apply to all connections (nil by default).
96
105
  :max_connections :: The maximum size of the connection pool (4 connections by default on most databases)
97
106
  :pool_timeout :: The number of seconds to wait if a connection cannot be acquired before raising an error (5 seconds by default)
98
- :preconnect :: Whether to automatically make the maximum number of connections when setting up the pool.
99
- Can be set to "concurrently" to connect in parallel.
100
107
  :single_threaded :: Whether to use a single-threaded (non-thread safe) connection pool
101
108
 
102
109
  == Adapter specific connection options
@@ -0,0 +1,31 @@
1
+ = New Features
2
+
3
+ * An instance-level skip_auto_validations method has been added to
4
+ the auto_validations plugin, allowing you to skip all or specific
5
+ types of auto validations inside the block:
6
+
7
+ model_instance.skip_auto_validations(:unique) do
8
+ puts model_instance.valid?
9
+ end
10
+
11
+ * A Database :preconnect_extensions option has been added. This
12
+ option is similar to :extensions, but the extensions are loaded
13
+ before the :preconnect option is processed. This allows you to
14
+ use the server_logging extension with the :preconnect option.
15
+
16
+ * For specifying custom table aliases when using eager_graph and
17
+ association_join, you can now use:
18
+
19
+ Sequel[:association].as(:table_alias)
20
+
21
+ in addition to:
22
+
23
+ Sequel.as(:association, :table_alias)
24
+
25
+ = Other Improvements
26
+
27
+ * The ado/mssql adapter now retrieves the number of deleted or
28
+ updated rows for a query without issuing a separate query.
29
+
30
+ * Sequel now avoids the use of Proc.new with an implicit block, as
31
+ that feature will be deprecated starting in Ruby 2.7.
@@ -111,7 +111,7 @@ module Sequel
111
111
  log_connection_yield(sql, conn){conn.Execute(sql)}
112
112
  last_insert_sql = "SELECT @@IDENTITY"
113
113
  res = log_connection_yield(last_insert_sql, conn){conn.Execute(last_insert_sql)}
114
- res.getRows.transpose.each{|r| return r.shift}
114
+ res.GetRows.transpose.each{|r| return r.shift}
115
115
  rescue ::WIN32OLERuntimeError => e
116
116
  raise_error(e)
117
117
  end
@@ -296,7 +296,7 @@ module Sequel
296
296
  execute_open_ado_schema(type, criteria) do |s|
297
297
  cols = []
298
298
  s.Fields.each{|f| cols << f.Name}
299
- s.getRows.transpose.each do |r|
299
+ s.GetRows.transpose.each do |r|
300
300
  row = {}
301
301
  cols.each{|c| row[c] = r.shift}
302
302
  yield row
@@ -7,17 +7,14 @@ module Sequel
7
7
  module MSSQL
8
8
  module DatabaseMethods
9
9
  include Sequel::MSSQL::DatabaseMethods
10
- # Issue a separate query to get the rows modified. ADO appears to
11
- # use pass by reference with an integer variable, which is
12
- # not supported directly in ruby, and I'm not aware of a workaround.
10
+
13
11
  def execute_dui(sql, opts=OPTS)
14
12
  return super unless @opts[:provider]
15
13
  synchronize(opts[:server]) do |conn|
16
14
  begin
17
- log_connection_yield(sql, conn){conn.Execute(sql)}
18
- rows_affected_sql = "SELECT @@ROWCOUNT AS AffectedRows"
19
- res = log_connection_yield(rows_affected_sql, conn){conn.Execute(rows_affected_sql)}
20
- res.getRows.transpose.each{|r| return r.shift}
15
+ sql = "SET NOCOUNT ON; #{sql}; SELECT @@ROWCOUNT"
16
+ rst = log_connection_yield(sql, conn){conn.Execute(sql)}
17
+ rst.GetRows[0][0]
21
18
  rescue ::WIN32OLERuntimeError => e
22
19
  raise_error(e)
23
20
  end
@@ -195,8 +195,8 @@ module Sequel
195
195
 
196
196
  # Set a conversion proc for the given oid. The callable can
197
197
  # be passed either as a argument or a block.
198
- def add_conversion_proc(oid, callable=Proc.new)
199
- conversion_procs[oid] = callable
198
+ def add_conversion_proc(oid, callable=nil, &block)
199
+ conversion_procs[oid] = callable || block
200
200
  end
201
201
 
202
202
  # Add a conversion proc for a named type, using the given block.
@@ -27,7 +27,7 @@ module Sequel
27
27
  :blob=>Sequel::SQL::Blob}.freeze
28
28
 
29
29
  # Nested hook Proc; each new hook Proc just wraps the previous one.
30
- @initialize_hook = Proc.new {|db| }
30
+ @initialize_hook = proc{|db| }
31
31
 
32
32
  # Register a hook that will be run when a new Database is instantiated. It is
33
33
  # called with the new database handle.
@@ -35,7 +35,7 @@ module Sequel
35
35
  raise Error, "must provide block to after_initialize" unless block
36
36
  Sequel.synchronize do
37
37
  previous = @initialize_hook
38
- @initialize_hook = Proc.new do |db|
38
+ @initialize_hook = proc do |db|
39
39
  previous.call(db)
40
40
  block.call(db)
41
41
  end
@@ -97,14 +97,19 @@ module Sequel
97
97
  # Accepts the following options:
98
98
  # :cache_schema :: Whether schema should be cached for this Database instance
99
99
  # :default_string_column_size :: The default size of string columns, 255 by default.
100
+ # :extensions :: Extensions to load into this Database instance. Can be a symbol, array of symbols,
101
+ # or string with extensions separated by columns. These extensions are loaded after
102
+ # connections are made by the :preconnect option.
100
103
  # :keep_reference :: Whether to keep a reference to this instance in Sequel::DATABASES, true by default.
101
104
  # :logger :: A specific logger to use.
102
105
  # :loggers :: An array of loggers to use.
103
106
  # :log_connection_info :: Whether connection information should be logged when logging queries.
104
107
  # :log_warn_duration :: The number of elapsed seconds after which queries should be logged at warn level.
105
- # :name :: A name to use for the Database object.
106
- # :preconnect :: Whether to automatically connect to the maximum number of servers. Can use a valid
107
- # of 'concurrently' to preconnect in separate threads.
108
+ # :name :: A name to use for the Database object, displayed in PoolTimeout .
109
+ # :preconnect :: Whether to setup the maximum number of connections during initialization.
110
+ # Can use a value of 'concurrently' to preconnect in separate threads.
111
+ # :preconnect_extensions :: Similar to the :extensions option, but loads the extensions before the
112
+ # connections are made by the :preconnect option.
108
113
  # :quote_identifiers :: Whether to quote identifiers.
109
114
  # :servers :: A hash specifying a server/shard specific options, keyed by shard symbol .
110
115
  # :single_threaded :: Whether to use a single-threaded connection pool.
@@ -147,23 +152,15 @@ module Sequel
147
152
  Sequel.synchronize{::Sequel::DATABASES.push(self)}
148
153
  end
149
154
  Sequel::Database.run_after_initialize(self)
155
+
156
+ initialize_load_extensions(:preconnect_extensions)
157
+
150
158
  if typecast_value_boolean(@opts[:preconnect]) && @pool.respond_to?(:preconnect, true)
151
159
  concurrent = typecast_value_string(@opts[:preconnect]) == "concurrently"
152
160
  @pool.send(:preconnect, concurrent)
153
161
  end
154
162
 
155
- case exts = @opts[:extensions]
156
- when String
157
- extension(*exts.split(',').map(&:to_sym))
158
- when Array
159
- extension(*exts)
160
- when Symbol
161
- extension(exts)
162
- when nil
163
- # nothing
164
- else
165
- raise Error, "unsupported Database :extensions option: #{@opts[:extensions].inspect}"
166
- end
163
+ initialize_load_extensions(:extensions)
167
164
  end
168
165
 
169
166
  # Freeze internal data structures for the Database instance.
@@ -412,6 +409,22 @@ module Sequel
412
409
  opts[:disconnect]
413
410
  end
414
411
 
412
+ # Load extensions during initialization from the given key in opts.
413
+ def initialize_load_extensions(key)
414
+ case exts = @opts[key]
415
+ when String
416
+ extension(*exts.split(',').map(&:to_sym))
417
+ when Array
418
+ extension(*exts)
419
+ when Symbol
420
+ extension(exts)
421
+ when nil
422
+ # nothing
423
+ else
424
+ raise Error, "unsupported Database #{key.inspect} option: #{@opts[key].inspect}"
425
+ end
426
+ end
427
+
415
428
  # Convert the given exception to an appropriate Sequel::DatabaseError
416
429
  # subclass, keeping message and backtrace.
417
430
  def raise_error(exception, opts=OPTS)
@@ -357,7 +357,8 @@ module Sequel
357
357
  end
358
358
 
359
359
  # Add a column with the given name, type, and opts.
360
- # See CreateTableGenerator#column for the available options.
360
+ # See CreateTableGenerator#column for the available options (except for +:index+, use a
361
+ # separate +add_index+ call to add an index for the column).
361
362
  #
362
363
  # add_column(:name, String) # ADD COLUMN name varchar(255)
363
364
  #
@@ -399,7 +400,8 @@ module Sequel
399
400
  end
400
401
 
401
402
  # Add a foreign key with the given name and referencing the given table.
402
- # See CreateTableGenerator#column for the available options.
403
+ # See CreateTableGenerator#column for the available options (except for +:index+, use a
404
+ # separate +add_index+ call to add an index for the column).
403
405
  #
404
406
  # You can also pass an array of column names for creating composite foreign
405
407
  # keys. In this case, it will assume the columns exist and will only add
@@ -58,7 +58,8 @@ module Sequel
58
58
  # # => 3
59
59
  # DB[:table].avg{function(column)} # SELECT avg(function(column)) FROM table LIMIT 1
60
60
  # # => 1
61
- def avg(arg=Sequel.virtual_row(&Proc.new))
61
+ def avg(arg=(no_arg = true), &block)
62
+ arg = Sequel.virtual_row(&block) if no_arg
62
63
  _aggregate(:avg, arg)
63
64
  end
64
65
 
@@ -450,7 +451,8 @@ module Sequel
450
451
  # # => 10
451
452
  # DB[:table].max{function(column)} # SELECT max(function(column)) FROM table LIMIT 1
452
453
  # # => 7
453
- def max(arg=Sequel.virtual_row(&Proc.new))
454
+ def max(arg=(no_arg = true), &block)
455
+ arg = Sequel.virtual_row(&block) if no_arg
454
456
  _aggregate(:max, arg)
455
457
  end
456
458
 
@@ -461,7 +463,8 @@ module Sequel
461
463
  # # => 1
462
464
  # DB[:table].min{function(column)} # SELECT min(function(column)) FROM table LIMIT 1
463
465
  # # => 0
464
- def min(arg=Sequel.virtual_row(&Proc.new))
466
+ def min(arg=(no_arg = true), &block)
467
+ arg = Sequel.virtual_row(&block) if no_arg
465
468
  _aggregate(:min, arg)
466
469
  end
467
470
 
@@ -733,7 +736,8 @@ module Sequel
733
736
  # # => 55
734
737
  # DB[:table].sum{function(column)} # SELECT sum(function(column)) FROM table LIMIT 1
735
738
  # # => 10
736
- def sum(arg=Sequel.virtual_row(&Proc.new))
739
+ def sum(arg=(no_arg = true), &block)
740
+ arg = Sequel.virtual_row(&block) if no_arg
737
741
  _aggregate(:sum, arg)
738
742
  end
739
743
 
@@ -41,7 +41,8 @@ module Sequel
41
41
  # # => 6
42
42
  # DB[:table].interval{function(column)} # SELECT (max(function(column)) - min(function(column))) FROM table LIMIT 1
43
43
  # # => 7
44
- def interval(column=Sequel.virtual_row(&Proc.new))
44
+ def interval(column=(no_arg = true), &block)
45
+ column = Sequel.virtual_row(&block) if no_arg
45
46
  if loader = cached_placeholder_literalizer(:_interval_loader) do |pl|
46
47
  arg = pl.arg
47
48
  aggregate_dataset.limit(1).select((SQL::Function.new(:max, arg) - SQL::Function.new(:min, arg)).as(:interval))
@@ -60,7 +61,8 @@ module Sequel
60
61
  # # => 1..10
61
62
  # DB[:table].interval{function(column)} # SELECT max(function(column)) AS v1, min(function(column)) AS v2 FROM table LIMIT 1
62
63
  # # => 0..7
63
- def range(column=Sequel.virtual_row(&Proc.new))
64
+ def range(column=(no_arg = true), &block)
65
+ column = Sequel.virtual_row(&block) if no_arg
64
66
  r = if loader = cached_placeholder_literalizer(:_range_loader) do |pl|
65
67
  arg = pl.arg
66
68
  aggregate_dataset.limit(1).select(SQL::Function.new(:min, arg).as(:v1), SQL::Function.new(:max, arg).as(:v2))
@@ -752,8 +752,8 @@ module Sequel
752
752
 
753
753
  # If +s+ is an array, map +s+ over the block. Otherwise, just call the
754
754
  # block with +s+.
755
- def transform(s)
756
- s.is_a?(Array) ? s.map(&Proc.new) : (yield s)
755
+ def transform(s, &block)
756
+ s.is_a?(Array) ? s.map(&block) : (yield s)
757
757
  end
758
758
 
759
759
  # What eager limit strategy should be used when true is given as the value,
@@ -3273,7 +3273,15 @@ module Sequel
3273
3273
  # per-call determining of the alias base.
3274
3274
  def eager_graph_check_association(model, association)
3275
3275
  if association.is_a?(SQL::AliasedExpression)
3276
- SQL::AliasedExpression.new(check_association(model, association.expression), association.alias)
3276
+ expr = association.expression
3277
+ if expr.is_a?(SQL::Identifier)
3278
+ expr = expr.value
3279
+ if expr.is_a?(String)
3280
+ expr = expr.to_sym
3281
+ end
3282
+ end
3283
+
3284
+ SQL::AliasedExpression.new(check_association(model, expr), association.alias)
3277
3285
  else
3278
3286
  check_association(model, association)
3279
3287
  end
@@ -324,14 +324,14 @@ module Sequel
324
324
  # Any public methods in the dataset module will have class methods created that
325
325
  # call the method on the dataset, assuming that the class method is not already
326
326
  # defined.
327
- def dataset_module(mod = nil)
327
+ def dataset_module(mod = nil, &block)
328
328
  if mod
329
- raise Error, "can't provide both argument and block to Model.dataset_module" if block_given?
329
+ raise Error, "can't provide both argument and block to Model.dataset_module" if block
330
330
  dataset_extend(mod)
331
331
  mod
332
332
  else
333
333
  @dataset_module ||= dataset_module_class.new(self)
334
- @dataset_module.module_eval(&Proc.new) if block_given?
334
+ @dataset_module.module_eval(&block) if block
335
335
  dataset_extend(@dataset_module)
336
336
  @dataset_module
337
337
  end
@@ -30,6 +30,12 @@ module Sequel
30
30
  #
31
31
  # Model.skip_auto_validations(:all)
32
32
  #
33
+ # It is possible to skip auto validations on a per-model-instance basis via:
34
+ #
35
+ # instance.skip_auto_validations(:unique, :not_null) do
36
+ # puts instance.valid?
37
+ # end
38
+ #
33
39
  # By default, the plugin uses a not_null validation for NOT NULL columns, but that
34
40
  # can be changed to a presence validation using an option:
35
41
  #
@@ -58,6 +64,7 @@ module Sequel
58
64
  MAX_LENGTH_OPTIONS = {:from=>:values, :allow_nil=>true}.freeze
59
65
  SCHEMA_TYPES_OPTIONS = NOT_NULL_OPTIONS
60
66
  UNIQUE_OPTIONS = NOT_NULL_OPTIONS
67
+ EMPTY_ARRAY = [].freeze
61
68
 
62
69
  def self.apply(model, opts=OPTS)
63
70
  model.instance_exec do
@@ -172,38 +179,50 @@ module Sequel
172
179
  end
173
180
 
174
181
  module InstanceMethods
182
+ # Skip the given types of auto validations on this instance inside the block.
183
+ def skip_auto_validations(*types)
184
+ types << :all if types.empty?
185
+ @_skip_auto_validations = types
186
+ yield
187
+ ensure
188
+ @_skip_auto_validations = nil
189
+ end
190
+
175
191
  # Validate the model's auto validations columns
176
192
  def validate
177
193
  super
194
+ skip = @_skip_auto_validations || EMPTY_ARRAY
195
+ return if skip.include?(:all)
178
196
  opts = model.auto_validate_options
179
197
 
180
- unless (not_null_columns = model.auto_validate_not_null_columns).empty?
181
- if model.auto_validate_presence?
182
- validates_presence(not_null_columns, opts[:not_null])
183
- else
184
- validates_not_null(not_null_columns, opts[:not_null])
198
+
199
+ unless skip.include?(:not_null)
200
+ not_null_method = model.auto_validate_presence? ? :validates_presence : :validates_not_null
201
+ unless (not_null_columns = model.auto_validate_not_null_columns).empty?
202
+ public_send(not_null_method, not_null_columns, opts[:not_null])
185
203
  end
186
- end
187
- unless (not_null_columns = model.auto_validate_explicit_not_null_columns).empty?
188
- if model.auto_validate_presence?
189
- validates_presence(not_null_columns, opts[:explicit_not_null])
190
- else
191
- validates_not_null(not_null_columns, opts[:explicit_not_null])
204
+ unless (not_null_columns = model.auto_validate_explicit_not_null_columns).empty?
205
+ public_send(not_null_method, not_null_columns, opts[:explicit_not_null])
192
206
  end
193
207
  end
194
- unless (max_length_columns = model.auto_validate_max_length_columns).empty?
208
+
209
+ unless skip.include?(:max_length) || (max_length_columns = model.auto_validate_max_length_columns).empty?
195
210
  max_length_columns.each do |col, len|
196
211
  validates_max_length(len, col, opts[:max_length])
197
212
  end
198
213
  end
199
214
 
200
- validates_schema_types(keys, opts[:schema_types]) if model.auto_validate_types?
215
+ unless skip.include?(:types) || !model.auto_validate_types?
216
+ validates_schema_types(keys, opts[:schema_types])
217
+ end
201
218
 
202
- unique_opts = Hash[opts[:unique]]
203
- if model.respond_to?(:sti_dataset)
204
- unique_opts[:dataset] = model.sti_dataset
219
+ unless skip.include?(:unique)
220
+ unique_opts = Hash[opts[:unique]]
221
+ if model.respond_to?(:sti_dataset)
222
+ unique_opts[:dataset] = model.sti_dataset
223
+ end
224
+ model.auto_validate_unique_columns.each{|cols| validates_unique(cols, unique_opts)}
205
225
  end
206
- model.auto_validate_unique_columns.each{|cols| validates_unique(cols, unique_opts)}
207
226
  end
208
227
  end
209
228
  end
data/lib/sequel/sql.rb CHANGED
@@ -18,7 +18,8 @@ module Sequel
18
18
  end
19
19
 
20
20
  # Time subclass that gets literalized with only the time value, so it operates
21
- # like a standard SQL time type.
21
+ # like a standard SQL time type. This type does not support timezones, by design,
22
+ # so it will not work correctly with <tt>time with time zone</tt> types.
22
23
  class SQLTime < ::Time
23
24
  @date = nil
24
25
 
@@ -6,7 +6,7 @@ module Sequel
6
6
 
7
7
  # The minor version of Sequel. Bumped for every non-patch level
8
8
  # release, generally around once a month.
9
- MINOR = 16
9
+ MINOR = 17
10
10
 
11
11
  # The tiny version of Sequel. Usually 0, only bumped for bugfix
12
12
  # releases that fix regressions from previous versions.
@@ -2607,7 +2607,7 @@ describe "Database extensions" do
2607
2607
  @db = Sequel.mock
2608
2608
  end
2609
2609
  after do
2610
- Sequel::Database.instance_variable_set(:@initialize_hook, Proc.new {|db| })
2610
+ Sequel::Database.instance_variable_set(:@initialize_hook, proc{|db| })
2611
2611
  end
2612
2612
 
2613
2613
  it "should be able to register an extension with a module have Database#extension extend the module" do
@@ -2676,6 +2676,29 @@ describe "Database extensions" do
2676
2676
  proc{Sequel.mock(:extensions=>nil).a}.must_raise NoMethodError
2677
2677
  proc{Sequel.mock(:extensions=>Object.new)}.must_raise Sequel::Error
2678
2678
  end
2679
+
2680
+ it "should support :preconnect_extensions Database option to load extensions before :preconnect" do
2681
+ x = []
2682
+ Sequel::Database.register_extension(:a, Module.new{define_singleton_method(:extended){|_| x << :a}})
2683
+ Sequel::Database.register_extension(:b, Module.new{define_singleton_method(:extended){|_| x << :b}})
2684
+ c = Class.new(Sequel::Database) do
2685
+ def dataset_class_default; Sequel::Dataset end
2686
+ define_method(:connect) do |_|
2687
+ x << :c
2688
+ :connect
2689
+ end
2690
+ end
2691
+
2692
+ db = c.new(:max_connections=>2, :preconnect=>true, :preconnect_extensions=>:a, :extensions=>:b)
2693
+ db.pool.size.must_equal db.pool.max_size
2694
+ x.must_equal [:a, :c, :c, :b]
2695
+
2696
+ x.clear
2697
+ db = c.new(:max_connections=>3, :preconnect=>:concurrently, :preconnect_extensions=>:b, :extensions=>:a)
2698
+ x.must_equal [:b, :c, :c, :c, :a]
2699
+ db.pool.size.must_equal db.pool.max_size
2700
+ end
2701
+
2679
2702
  end
2680
2703
 
2681
2704
  describe "Database specific exception classes" do
@@ -2707,7 +2730,7 @@ end
2707
2730
 
2708
2731
  describe "Database.after_initialize" do
2709
2732
  after do
2710
- Sequel::Database.instance_variable_set(:@initialize_hook, Proc.new {|db| })
2733
+ Sequel::Database.instance_variable_set(:@initialize_hook, proc{|db| })
2711
2734
  end
2712
2735
 
2713
2736
  it "should allow a block to be run after each new instance is created" do
@@ -48,7 +48,7 @@ describe "Dataset#clone" do
48
48
  end
49
49
 
50
50
  it "should create an exact copy of the dataset" do
51
- @dataset = @dataset.with_row_proc(Proc.new{|r| r})
51
+ @dataset = @dataset.with_row_proc(proc{|r| r})
52
52
  clone = @dataset.clone
53
53
  @dataset.dup.must_be_same_as @dataset
54
54
 
@@ -63,7 +63,7 @@ describe "Dataset#clone" do
63
63
  end
64
64
 
65
65
  it "should create an exact copy of the dataset when given an empty hash" do
66
- @dataset = @dataset.with_row_proc(Proc.new{|r| r})
66
+ @dataset = @dataset.with_row_proc(proc{|r| r})
67
67
  clone = @dataset.clone({})
68
68
 
69
69
  clone.object_id.wont_equal @dataset.object_id
@@ -1877,7 +1877,7 @@ end
1877
1877
 
1878
1878
  describe "Dataset#naked" do
1879
1879
  it "should returned clone dataset without row_proc" do
1880
- d = Sequel.mock.dataset.with_row_proc(Proc.new{|r| r})
1880
+ d = Sequel.mock.dataset.with_row_proc(proc{|r| r})
1881
1881
  d.naked.row_proc.must_be_nil
1882
1882
  d.row_proc.wont_be_nil
1883
1883
  end
@@ -96,6 +96,12 @@ describe "Sequel::Plugins::AutoValidations" do
96
96
  it "should allow skipping validations by type" do
97
97
  @c = Class.new(@c)
98
98
  @m = @c.new
99
+ @m.skip_auto_validations(:not_null) do
100
+ @m.valid?.must_equal true
101
+ @m.nnd = nil
102
+ @m.valid?.must_equal true
103
+ end
104
+ @m.set(:nnd => 'nnd')
99
105
  @c.skip_auto_validations(:not_null)
100
106
  @m.valid?.must_equal true
101
107
  @m.nnd = nil
@@ -105,10 +111,20 @@ describe "Sequel::Plugins::AutoValidations" do
105
111
  @m.valid?.must_equal false
106
112
  @m.errors.must_equal(:d=>["is not a valid date"], :num=>["is not a valid integer"])
107
113
 
114
+ @m.skip_auto_validations(:types, :unique) do
115
+ @m.valid?.must_equal true
116
+ end
117
+ @m.skip_auto_validations(:types) do
118
+ @m.valid?.must_equal false
119
+ @m.errors.must_equal([:name, :num]=>["is already taken"])
120
+ end
108
121
  @c.skip_auto_validations(:types)
109
122
  @m.valid?.must_equal false
110
123
  @m.errors.must_equal([:name, :num]=>["is already taken"])
111
124
 
125
+ @m.skip_auto_validations(:unique) do
126
+ @m.valid?.must_equal true
127
+ end
112
128
  @c.skip_auto_validations(:unique)
113
129
  @m.valid?.must_equal true
114
130
 
@@ -116,6 +132,9 @@ describe "Sequel::Plugins::AutoValidations" do
116
132
  @m.valid?.must_equal false
117
133
  @m.errors.must_equal(:name=>["is longer than 50 characters"])
118
134
 
135
+ @m.skip_auto_validations(:max_length) do
136
+ @m.valid?.must_equal true
137
+ end
119
138
  @c.skip_auto_validations(:max_length)
120
139
  @m.valid?.must_equal true
121
140
  end
@@ -123,6 +142,14 @@ describe "Sequel::Plugins::AutoValidations" do
123
142
  it "should allow skipping all auto validations" do
124
143
  @c = Class.new(@c)
125
144
  @m = @c.new
145
+ @m.skip_auto_validations(:all) do
146
+ @m.valid?.must_equal true
147
+ @m.set(:d=>'/', :num=>'a', :name=>'1')
148
+ @m.valid?.must_equal true
149
+ @m.set(:name=>'a'*51)
150
+ @m.valid?.must_equal true
151
+ end
152
+ @m = @c.new
126
153
  @c.skip_auto_validations(:all)
127
154
  @m.valid?.must_equal true
128
155
  @m.set(:d=>'/', :num=>'a', :name=>'1')
@@ -120,7 +120,7 @@ describe "Reversible Migrations with Sequel.migration{change{}}" do
120
120
  end
121
121
  end
122
122
  @db = @c.new
123
- @p = Proc.new do
123
+ @p = proc do
124
124
  create_table(:a, :foo=>:bar){Integer :a}
125
125
  add_column :a, :b, String
126
126
  add_index :a, :b
@@ -4247,6 +4247,12 @@ describe "Sequel::Model Associations with clashing column names" do
4247
4247
  @Bar.exclude(Sequel::SQL::BooleanExpression.new(:IN, :foo, Sequel.function(:srf))).sql.must_equal 'SELECT * FROM bars WHERE (foo NOT IN srf())'
4248
4248
  end
4249
4249
 
4250
+ it "should have working eager graphing methods when using SQL::Identifier inside SQL::AliasedExpression" do
4251
+ @db.fetch = {:id=>1, :object_id=>2, :f_id=>1, :f_object_id=>2}
4252
+ @Bar.eager_graph(Sequel[:foo].as(:f)).all.map{|o| [o, o.foo]}.must_equal [[@bar, @foo]]
4253
+ @db.sqls.must_equal ["SELECT bars.id, bars.object_id, f.id AS f_id, f.object_id AS f_object_id FROM bars LEFT OUTER JOIN foos AS f ON (f.object_id = bars.object_id)"]
4254
+ end
4255
+
4250
4256
  it "should have working filter by associations with model instances" do
4251
4257
  @Bar.first(:foo=>@foo).must_equal @bar
4252
4258
  @db.sqls.must_equal ["SELECT * FROM bars WHERE (bars.object_id = 2) LIMIT 1"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.16.0
4
+ version: 5.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-02 00:00:00.000000000 Z
11
+ date: 2019-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -200,6 +200,7 @@ extra_rdoc_files:
200
200
  - doc/release_notes/5.14.0.txt
201
201
  - doc/release_notes/5.15.0.txt
202
202
  - doc/release_notes/5.16.0.txt
203
+ - doc/release_notes/5.17.0.txt
203
204
  files:
204
205
  - CHANGELOG
205
206
  - MIT-LICENSE
@@ -286,6 +287,7 @@ files:
286
287
  - doc/release_notes/5.14.0.txt
287
288
  - doc/release_notes/5.15.0.txt
288
289
  - doc/release_notes/5.16.0.txt
290
+ - doc/release_notes/5.17.0.txt
289
291
  - doc/release_notes/5.2.0.txt
290
292
  - doc/release_notes/5.3.0.txt
291
293
  - doc/release_notes/5.4.0.txt