Class Array
In: lib/sequel/extensions/core_extensions.rb
lib/sequel/extensions/pg_json.rb
lib/sequel/extensions/pg_row.rb
lib/sequel/extensions/pg_array.rb
lib/sequel/deprecated_core_extensions.rb
Parent: Object

Sequel extends Array to add methods to implement the SQL DSL. Most of these methods require that the array not be empty and that it must consist solely of other arrays that have exactly two elements.

Methods

Public Instance methods

[Source]

    # File lib/sequel/deprecated_core_extensions.rb, line 11
11:   def case(*args)
12:     Sequel::Deprecation.deprecate('Array#case', 'Please use Sequel.case instead, or Sequel.extension(:core_extensions) to continue using it')
13:     ::Sequel::SQL::CaseExpression.new(self, *args)
14:   end

Return a Sequel::SQL::CaseExpression with this array as the conditions and the given default value and expression.

  [[{:a=>[2,3]}, 1]].case(0) # SQL: CASE WHEN a IN (2, 3) THEN 1 ELSE 0 END
  [[:a, 1], [:b, 2]].case(:d, :c) # SQL: CASE c WHEN a THEN 1 WHEN b THEN 2 ELSE d END

[Source]

    # File lib/sequel/extensions/core_extensions.rb, line 35
35:   def case(*args)
36:     ::Sequel::SQL::CaseExpression.new(self, *args)
37:   end

Return a PGArray proxy to the receiver, using a specific database type if given. This is mostly useful as a short cut for creating PGArray objects that didn‘t come from the database.

[Source]

     # File lib/sequel/extensions/pg_array.rb, line 599
599:     def pg_array(type=nil)
600:       Sequel::Postgres::PGArray.new(self, type)
601:     end

Return a Sequel::Postgres::JSONArray proxy to the receiver. This is mostly useful as a short cut for creating JSONArray objects that didn‘t come from the database.

[Source]

     # File lib/sequel/extensions/pg_json.rb, line 208
208:     def pg_json
209:       Sequel::Postgres::JSONArray.new(self)
210:     end

Wraps the receiver in an anonymous Sequel::Postgres::PGRow::ArrayRow instance.

[Source]

     # File lib/sequel/extensions/pg_row.rb, line 596
596:     def pg_row
597:       Sequel::Postgres::PGRow::ArrayRow.new(self)
598:     end
sql_array()

Alias for sql_value_list

sql_array()

Alias for sql_value_list

Return a Sequel::SQL::BooleanExpression created from this array, matching all of the conditions. Rarely do you need to call this explicitly, as Sequel generally assumes that arrays of two element arrays specify this type of condition. One case where it can be necessary to use this is if you are using the object as a value in a filter hash and want to use the = operator instead of the IN operator (which is used by default for arrays of two element arrays).

  [[:a, true]].sql_expr # SQL: a IS TRUE
  [[:a, 1], [:b, [2, 3]]].sql_expr # SQL: a = 1 AND b IN (2, 3)

[Source]

    # File lib/sequel/extensions/core_extensions.rb, line 64
64:   def sql_expr
65:     Sequel.expr(self)
66:   end

[Source]

    # File lib/sequel/deprecated_core_extensions.rb, line 22
22:   def sql_expr
23:     Sequel::Deprecation.deprecate('Array#sql_expr', 'Please use Sequel.expr instead, or Sequel.extension(:core_extensions) to continue using it')
24:     Sequel.expr(self)
25:   end

[Source]

    # File lib/sequel/deprecated_core_extensions.rb, line 27
27:   def sql_negate
28:     Sequel::Deprecation.deprecate('Array#sql_negate', 'Please use Sequel.negate instead, or Sequel.extension(:core_extensions) to continue using it')
29:     Sequel.negate(self)
30:   end

Return a Sequel::SQL::BooleanExpression created from this array, matching none of the conditions.

  [[:a, true]].sql_negate # SQL: a IS NOT TRUE
  [[:a, 1], [:b, [2, 3]]].sql_negate # SQL: a != 1 AND b NOT IN (2, 3)

[Source]

    # File lib/sequel/extensions/core_extensions.rb, line 73
73:   def sql_negate
74:     Sequel.negate(self)
75:   end

Return a Sequel::SQL::BooleanExpression created from this array, matching any of the conditions.

  [[:a, true]].sql_or # SQL: a IS TRUE
  [[:a, 1], [:b, [2, 3]]].sql_or # SQL: a = 1 OR b IN (2, 3)

[Source]

    # File lib/sequel/extensions/core_extensions.rb, line 82
82:   def sql_or
83:     Sequel.or(self)
84:   end

[Source]

    # File lib/sequel/deprecated_core_extensions.rb, line 32
32:   def sql_or
33:     Sequel::Deprecation.deprecate('Array#sql_or', 'Please use Sequel.or instead, or Sequel.extension(:core_extensions) to continue using it')
34:     Sequel.or(self)
35:   end

Return a Sequel::SQL::StringExpression representing an SQL string made up of the concatenation of this array‘s elements. If an argument is passed it is used in between each element of the array in the SQL concatenation.

  [:a].sql_string_join # SQL: a
  [:a, :b].sql_string_join # SQL: a || b
  [:a, 'b'].sql_string_join # SQL: a || 'b'
  ['a', :b].sql_string_join(' ') # SQL: 'a' || ' ' || b

[Source]

    # File lib/sequel/extensions/core_extensions.rb, line 95
95:   def sql_string_join(joiner=nil)
96:     Sequel.join(self, joiner)
97:   end

[Source]

    # File lib/sequel/deprecated_core_extensions.rb, line 37
37:   def sql_string_join(joiner=nil)
38:     Sequel::Deprecation.deprecate('Array#sql_string_join', 'Please use Sequel.join instead, or Sequel.extension(:core_extensions) to continue using it')
39:     Sequel.join(self, joiner)
40:   end

[Source]

    # File lib/sequel/deprecated_core_extensions.rb, line 16
16:   def sql_value_list
17:     Sequel::Deprecation.deprecate('Array#sql_value_list/Array#sql_array', 'Please use Sequel.value_list instead, or Sequel.extension(:core_extensions) to continue using it')
18:     ::Sequel::SQL::ValueList.new(self)
19:   end

Return a Sequel::SQL::ValueList created from this array. Used if this array contains all two element arrays and you want it treated as an SQL value list (IN predicate) instead of as a conditions specifier (similar to a hash). This is not necessary if you are using this array as a value in a filter, but may be necessary if you are using it as a value with placeholder SQL:

  DB[:a].filter([:a, :b]=>[[1, 2], [3, 4]]) # SQL: (a, b) IN ((1, 2), (3, 4))
  DB[:a].filter('(a, b) IN ?', [[1, 2], [3, 4]]) # SQL: (a, b) IN ((1 = 2) AND (3 = 4))
  DB[:a].filter('(a, b) IN ?', [[1, 2], [3, 4]].sql_value_list) # SQL: (a, b) IN ((1, 2), (3, 4))

[Source]

    # File lib/sequel/extensions/core_extensions.rb, line 48
48:   def sql_value_list
49:     ::Sequel::SQL::ValueList.new(self)
50:   end

[Source]

   # File lib/sequel/deprecated_core_extensions.rb, line 6
6:   def ~
7:     Sequel::Deprecation.deprecate('Array#~', 'Please use Sequel.~ instead, or Sequel.extension(:core_extensions) to continue using it')
8:     Sequel.~(self)
9:   end

Return a Sequel::SQL::BooleanExpression created from this array, not matching all of the conditions.

  ~[[:a, true]] # SQL: a IS NOT TRUE
  ~[[:a, 1], [:b, [2, 3]]] # SQL: a != 1 OR b NOT IN (2, 3)

[Source]

    # File lib/sequel/extensions/core_extensions.rb, line 26
26:   def ~
27:     Sequel.~(self)
28:   end

[Validate]