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, #eql?, #hash, inherited, #inspect, #lit, #sql_literal

Constructor Details

#initialize(f, sub) ⇒ Subscript

Set the array column and subscripts to the given arguments



1716
1717
1718
# File 'lib/sequel/sql.rb', line 1716

def initialize(f, sub)
  @f, @sub = f, sub
end

Instance Attribute Details

#fObject (readonly)

The SQL array column



1710
1711
1712
# File 'lib/sequel/sql.rb', line 1710

def f
  @f
end

#subObject (readonly)

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



1713
1714
1715
# File 'lib/sequel/sql.rb', line 1713

def sub
  @sub
end

Instance Method Details

#[](sub) ⇒ Object

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

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


1734
1735
1736
# File 'lib/sequel/sql.rb', line 1734

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.

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


1725
1726
1727
# File 'lib/sequel/sql.rb', line 1725

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