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, #sqlite_jsonb_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



1811
1812
1813
1814
1815
# File 'lib/sequel/sql.rb', line 1811

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

Instance Attribute Details

#expressionObject (readonly) Also known as: f

The SQL array column



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

def expression
  @expression
end

#subObject (readonly)

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



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

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]


1831
1832
1833
# File 'lib/sequel/sql.rb', line 1831

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]


1822
1823
1824
# File 'lib/sequel/sql.rb', line 1822

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