Class: Sequel::SQL::Subscript

Inherits:
GenericExpression show all
Defined in:
lib/sequel/sql.rb

Overview

Represents an SQL array access, with multiple possible arguments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Postgres::HStoreOpMethods

#hstore

Methods included from Postgres::RangeOpMethods

#pg_range

Methods included from Postgres::ArrayOpMethods

#pg_array

Methods included from Postgres::JSONOpMethods

#pg_json, #pg_jsonb

Methods included from Postgres::InetOpMethods

#pg_inet

Methods included from Postgres::PGRowOp::ExpressionMethods

#pg_row

Methods included from SubscriptMethods

#sql_subscript

Methods included from StringMethods

#ilike, #like

Methods included from PatternMatchMethods

#!~, #=~

Methods included from OrderMethods

#asc, #desc

Methods included from NumericMethods

#+, #coerce

Methods included from ComplexExpressionMethods

#extract, #sql_boolean, #sql_number, #sql_string

Methods included from CastMethods

#cast, #cast_numeric, #cast_string

Methods included from BooleanMethods

#~

Methods included from AliasMethods

#as

Methods inherited from Expression

#==, attr_reader, #clone, #eql?, #hash, inherited, #inspect

Constructor Details

#initialize(expression, sub) ⇒ Subscript

Set the array column and subscripts to the given arguments


1743
1744
1745
1746
1747
# File 'lib/sequel/sql.rb', line 1743

def initialize(expression, sub)
  @expression = expression
  @sub = sub
  freeze
end

Instance Attribute Details

#expressionObject (readonly) Also known as: f

The SQL array column


1736
1737
1738
# File 'lib/sequel/sql.rb', line 1736

def expression
  @expression
end

#subObject (readonly)

The array of subscripts to use (should be an array of numbers)


1740
1741
1742
# File 'lib/sequel/sql.rb', line 1740

def sub
  @sub
end

Instance Method Details

#[](sub) ⇒ Object

Create a new Subscript by accessing a subarray of a multidimensional array.

Sequel[:a].sql_subscript(2) # a[2]
Sequel[:a].sql_subscript(2)[1] # a[2][1]

1763
1764
1765
# File 'lib/sequel/sql.rb', line 1763

def [](sub)
  Subscript.new(self, Array(sub))
end

#|(sub) ⇒ Object

Create a new Subscript appending the given subscript(s) to the current array of subscripts.

Sequel[:a].sql_subscript(2) # a[2]
Sequel[:a].sql_subscript(2) | 1 # a[2, 1]

1754
1755
1756
# File 'lib/sequel/sql.rb', line 1754

def |(sub)
  Subscript.new(@expression, @sub + Array(sub))
end