class Sequel::Postgres::PGRowOp

  1. lib/sequel/extensions/pg_row_ops.rb
Superclass: Sequel::SQL::PlaceholderLiteralString

This class represents a composite type expression reference.

Methods

Public Class

  1. wrap

Public Instance

  1. *
  2. []
  3. splat

Constants

QUALIFY = ['(', ').'].freeze.each(&:freeze)  
ROW = ['(', '.*)'].freeze.each(&:freeze)  
ROW_CAST = ['(', '.*)::'].freeze.each(&:freeze)  
WRAP = [""].freeze.each(&:freeze)  

Public Class methods

wrap(expr)

Wrap the expression in a PGRowOp, without changing the SQL it would use.

[show source]
    # File lib/sequel/extensions/pg_row_ops.rb
 98 def self.wrap(expr)
 99   PGRowOp.new(WRAP, [expr])
100 end

Public Instance methods

*(ce=(arg=false;nil))

Use the (identifier).* syntax to reference the members of the composite type as separate columns. Generally used when you want to expand the columns of a composite type to be separate columns in the result set.

Sequel.pg_row_op(:a).*     # (a).*
Sequel.pg_row_op(:a)[:b].* # ((a).b).*
[show source]
    # File lib/sequel/extensions/pg_row_ops.rb
123 def *(ce=(arg=false;nil))
124   if arg == false
125     Sequel::SQL::ColumnAll.new([self])
126   else
127     super(ce)
128   end
129 end
[](member)

Access a member of the composite type if given a symbol or an SQL::Identifier. For all other access, assuming the pg_array_ops extension is loaded and that it represents an array access. In either case, return a PgRowOp so that access can be cascaded.

[show source]
    # File lib/sequel/extensions/pg_row_ops.rb
107 def [](member)
108   case member
109   when Symbol, SQL::Identifier
110     PGRowOp.new(QUALIFY, [self, member])
111   else
112     PGRowOp.wrap(Sequel.pg_array_op(self)[member])
113   end
114 end
splat(cast_to=nil)

Use the (identifier.*) syntax to indicate that this expression represents the composite type of one of the tables being referenced, if it has the same name as one of the columns. If the cast_to argument is given, also cast the expression to that type (which should be a symbol representing the composite type). This is used if you want to return whole table row as a composite type.

Sequel.pg_row_op(:a).splat[:b] # (a.*).b
Sequel.pg_row_op(:a).splat(:a) # (a.*)::a
[show source]
    # File lib/sequel/extensions/pg_row_ops.rb
142 def splat(cast_to=nil)
143   if args.length > 1
144     raise Error, 'cannot splat a PGRowOp with multiple arguments'
145   end
146 
147   if cast_to
148     PGRowOp.new(ROW_CAST, args + [cast_to])
149   else
150     PGRowOp.new(ROW, args)
151   end
152 end