Class | Sequel::Postgres::PGRowOp |
In: |
lib/sequel/extensions/pg_row_ops.rb
|
Parent: | SQL::PlaceholderLiteralString |
OPEN | = | '('.freeze |
CLOSE_DOT | = | ').'.freeze |
CLOSE_STAR | = | '.*)'.freeze |
CLOSE_STAR_CAST | = | '.*)::'.freeze |
EMPTY | = | "".freeze |
ROW | = | [OPEN, CLOSE_STAR].freeze |
ROW_CAST | = | [OPEN, CLOSE_STAR_CAST].freeze |
QUALIFY | = | [OPEN, CLOSE_DOT].freeze |
WRAP | = | [EMPTY].freeze |
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).*
# File lib/sequel/extensions/pg_row_ops.rb, line 128 128: def *(ce=(arg=false;nil)) 129: if arg == false 130: Sequel::SQL::ColumnAll.new([self]) 131: else 132: super(ce) 133: end 134: end
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.
# File lib/sequel/extensions/pg_row_ops.rb, line 112 112: def [](member) 113: case member 114: when Symbol, SQL::Identifier 115: PGRowOp.new(QUALIFY, [self, member]) 116: else 117: PGRowOp.wrap(Sequel.pg_array_op(self)[member]) 118: end 119: end
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
# File lib/sequel/extensions/pg_row_ops.rb, line 147 147: def splat(cast_to=nil) 148: if args.length > 1 149: raise Error, 'cannot splat a PGRowOp with multiple arguments' 150: end 151: 152: if cast_to 153: PGRowOp.new(ROW_CAST, args + [cast_to]) 154: else 155: PGRowOp.new(ROW, args) 156: end 157: end