sequel 5.105.0 → 5.106.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa9e8681d693c24d9f5dc7f6369be50dfcbf73c648402ec486e9ba69d5792f76
4
- data.tar.gz: 7de020c93e5388ea9d58bd6e4d601bd06b240684e4c9001985549fd3b1c2d665
3
+ metadata.gz: 93dd74cb4407d389f289342898c26327d91db1ddd733478461bd8620a3a1771b
4
+ data.tar.gz: b00796ca61d19f2d9aeaaa764565893e73f5dd4c0752e11bd38635fdb94b1cea
5
5
  SHA512:
6
- metadata.gz: 34030c2c1a045fa5fc36a6a36e1414960315469d415be97c3734fea182e63224c86c0882fa1958d5549f77c420879f6402af61a1756a4b7575a315ceb9c67f11
7
- data.tar.gz: ea08def92c00668ca1898eac5a3dd37b50aeb1f81379e7c3ab19544e01cc5ef0c0c54786fc2a76f885e14b71534a3895451f33891cb374b3a3f10c08b0244d8a
6
+ metadata.gz: 2502a507d57a7f64dae3ddc9e736254461a3a05f15f95a4835e2ddd83cb3cf3a9f6719f97e6b05239508d4e8445cff8b502198d40eea9f2c0af9d7ea385f829f
7
+ data.tar.gz: 8f3e230dc402a4e9d4b2c1d60fb5bdcac580f8368a2ad79a132a29348df8bce6b78f983658c6cf1e406b53164f79f1103cdbfb8ccfd29d0ec90db48a57f348a2
@@ -2133,6 +2133,26 @@ module Sequel
2133
2133
  cached_lock_style_dataset(:_for_key_share_ds, :key_share)
2134
2134
  end
2135
2135
 
2136
+ # Set FOR PORTION OF clause for UPDATE and DELETE statements.
2137
+ # The first argument is the range or multirange column. If two arguments
2138
+ # are provided, the second argument is an expression with the same
2139
+ # database type as the first argument. If three arguments are provided,
2140
+ # the second specifies the inclusive start of the portion to update and the third
2141
+ # specifies the exclusive end of portion to update. When using the three argument
2142
+ # form, nil can be provided as the second or third argument to have the start or
2143
+ # end of the portion be unbounded. Supported on PostgreSQL 19+.
2144
+ # Example:
2145
+ #
2146
+ # DB[:t].for_portion_of(:rc, Sequel.function(:int4range, 1, 2)).update(c: 3)
2147
+ # # UPDATE t FOR PORTION OF rc (int4range(1, 2)) SET c = 3
2148
+ #
2149
+ # DB[:t].for_portion_of(:rc, 1, 2).update(c: 3)
2150
+ # # UPDATE t FOR PORTION OF rc FROM 1 TO 2 SET c = 3
2151
+ def for_portion_of(column, range, to=(arg_not_given=true))
2152
+ range = [range, to].freeze unless arg_not_given
2153
+ clone(:for_portion_of => [column, range].freeze)
2154
+ end
2155
+
2136
2156
  # Return a cloned dataset which will use FOR NO KEY UPDATE to lock returned rows.
2137
2157
  # This is generally a better choice than using for_update on PostgreSQL, unless
2138
2158
  # you will be deleting the row or modifying a key column. Supported on PostgreSQL 9.3+.
@@ -2635,10 +2655,11 @@ module Sequel
2635
2655
  "'%Y-%m-%d %H:%M:%S.%6N%z'"
2636
2656
  end
2637
2657
 
2638
- # Only include the primary table in the main delete clause
2658
+ # Only include the primary table in the main delete clause.
2659
+ # Support FOR PORTION OF.
2639
2660
  def delete_from_sql(sql)
2640
2661
  sql << ' FROM '
2641
- source_list_append(sql, @opts[:from][0..0])
2662
+ table_for_portion_of_sql_append(sql)
2642
2663
  end
2643
2664
 
2644
2665
  # Use USING to specify additional tables in a delete query
@@ -2723,6 +2744,32 @@ module Sequel
2723
2744
  origin
2724
2745
  end
2725
2746
 
2747
+ # Add FOR PORTION OF SQL if the dataset uses it.
2748
+ def table_for_portion_of_sql_append(sql)
2749
+ fpo_column, fpo_range = @opts[:for_portion_of]
2750
+ if fpo_column
2751
+ table, aliaz = split_alias(@opts[:from].first)
2752
+ source_list_append(sql, [table])
2753
+ sql << ' FOR PORTION OF '
2754
+ literal_append(sql, fpo_column)
2755
+
2756
+ if fpo_range.is_a?(Array)
2757
+ fpo_start, fpo_end = fpo_range
2758
+ sql << ' FROM '
2759
+ literal_append(sql, fpo_start)
2760
+ sql << ' TO '
2761
+ literal_append(sql, fpo_end)
2762
+ else
2763
+ sql << ' ('
2764
+ literal_append(sql, fpo_range)
2765
+ sql << ')'
2766
+ end
2767
+ as_sql_append(sql, aliaz) if aliaz
2768
+ else
2769
+ source_list_append(sql, @opts[:from][0..0])
2770
+ end
2771
+ end
2772
+
2726
2773
  # Add ON CONFLICT clause if it should be used
2727
2774
  def insert_conflict_sql(sql)
2728
2775
  if opts = @opts[:insert_conflict]
@@ -3012,10 +3059,10 @@ module Sequel
3012
3059
  join_from_sql(:FROM, sql)
3013
3060
  end
3014
3061
 
3015
- # Only include the primary table in the main update clause
3062
+ # Support FOR PORTION OF.
3016
3063
  def update_table_sql(sql)
3017
3064
  sql << ' '
3018
- source_list_append(sql, @opts[:from][0..0])
3065
+ table_for_portion_of_sql_append(sql)
3019
3066
  end
3020
3067
  end
3021
3068
  end
@@ -562,6 +562,7 @@ module Sequel
562
562
  end
563
563
 
564
564
  if window = opts[:over]
565
+ sql << ' IGNORE NULLS' if window.opts[:ignore_nulls]
565
566
  sql << ' OVER '
566
567
  window_sql_append(sql, window.opts)
567
568
  end
data/lib/sequel/sql.rb CHANGED
@@ -1323,6 +1323,7 @@ module Sequel
1323
1323
  # in this module which can be required at the top level to get
1324
1324
  # direct access to the constants.
1325
1325
  module Constants
1326
+ ALL = Constant.new(:ALL)
1326
1327
  CURRENT_DATE = Constant.new(:CURRENT_DATE)
1327
1328
  CURRENT_TIME = Constant.new(:CURRENT_TIME)
1328
1329
  CURRENT_TIMESTAMP = Constant.new(:CURRENT_TIMESTAMP)
@@ -1992,6 +1993,8 @@ module Sequel
1992
1993
  # for rows following
1993
1994
  # :exclude :: Which rows to exclude. Possible values are :current, :ties, :group
1994
1995
  # :no_others.
1996
+ # :ignore_nulls :: Can be set to :ignore for IGNORE NULLS (supported on PostgreSQL 19+ for
1997
+ # a subset of default window functions)
1995
1998
  # :order :: order on the column(s) given
1996
1999
  # :partition :: partition/group on the column(s) given
1997
2000
  # :window :: base results on a previously specified named window
@@ -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 = 105
9
+ MINOR = 106
10
10
 
11
11
  # The tiny version of Sequel. Usually 0, only bumped for bugfix
12
12
  # releases that fix regressions from previous versions.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.105.0
4
+ version: 5.106.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans