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 IsDistinctFrom::Methods

#is_distinct_from

Methods included from Sequel::SQLite::JSONOpMethods

#sqlite_json_op

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

#escaped_ilike, #escaped_like, #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



1808
1809
1810
1811
1812
# File 'lib/sequel/sql.rb', line 1808

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

Instance Attribute Details

#expressionObject (readonly) Also known as: f

The SQL array column



1801
1802
1803
# File 'lib/sequel/sql.rb', line 1801

def expression
  @expression
end

#subObject (readonly)

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



1805
1806
1807
# File 'lib/sequel/sql.rb', line 1805

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]


1828
1829
1830
# File 'lib/sequel/sql.rb', line 1828

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]


1819
1820
1821
# File 'lib/sequel/sql.rb', line 1819

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