class Array

  1. lib/sequel/extensions/core_extensions.rb
  2. lib/sequel/extensions/pg_array.rb
  3. lib/sequel/extensions/pg_json.rb
  4. lib/sequel/extensions/pg_row.rb
  5. show all
Superclass: 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.

Public Instance methods

case(*args)

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
[show source]
   # File lib/sequel/extensions/core_extensions.rb
35 def case(*args)
36   ::Sequel::SQL::CaseExpression.new(self, *args)
37 end
pg_array(type=nil)

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.

[show source]
    # File lib/sequel/extensions/pg_array.rb
512 def pg_array(type=nil)
513   Sequel::Postgres::PGArray.new(self, type)
514 end
pg_json()

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.

[show source]
    # File lib/sequel/extensions/pg_json.rb
594 def pg_json
595   Sequel::Postgres::JSONArray.new(self)
596 end
pg_jsonb()

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.

[show source]
    # File lib/sequel/extensions/pg_json.rb
601 def pg_jsonb
602   Sequel::Postgres::JSONBArray.new(self)
603 end
pg_row()

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

[show source]
    # File lib/sequel/extensions/pg_row.rb
567 def pg_row
568   Sequel::Postgres::PGRow::ArrayRow.new(self)
569 end
sql_expr()

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)))
[show source]
   # File lib/sequel/extensions/core_extensions.rb
61 def sql_expr
62   Sequel[self]
63 end
sql_negate()

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)))
[show source]
   # File lib/sequel/extensions/core_extensions.rb
70 def sql_negate
71   Sequel.negate(self)
72 end
sql_or()

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)))
[show source]
   # File lib/sequel/extensions/core_extensions.rb
79 def sql_or
80   Sequel.or(self)
81 end
sql_string_join(joiner=nil)

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)
[show source]
   # File lib/sequel/extensions/core_extensions.rb
92 def sql_string_join(joiner=nil)
93   Sequel.join(self, joiner)
94 end
sql_value_list()

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].where([:a, :b]=>[[1, 2], [3, 4]]) # SQL: ((a, b) IN ((1, 2), (3, 4)))
DB[:a].where('(a, b) IN ?', [[1, 2], [3, 4]]) # SQL: ((a, b) IN ((1 = 2) AND (3 = 4)))
DB[:a].where('(a, b) IN ?', [[1, 2], [3, 4]].sql_value_list) # SQL: ((a, b) IN ((1, 2), (3, 4)))
[show source]
   # File lib/sequel/extensions/core_extensions.rb
48 def sql_value_list
49   ::Sequel::SQL::ValueList.new(self)
50 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)))
[show source]
   # File lib/sequel/extensions/core_extensions.rb
26 def ~
27   Sequel.~(self)
28 end