Class: Sequel::Postgres::PGRowOp
- Inherits:
-
SQL::PlaceholderLiteralString
- Object
- SQL::Expression
- SQL::GenericExpression
- SQL::PlaceholderLiteralString
- Sequel::Postgres::PGRowOp
- Defined in:
- lib/sequel/extensions/pg_row_ops.rb
Overview
This class represents a composite type expression reference.
Defined Under Namespace
Modules: ExpressionMethods
Constant Summary collapse
- 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
Instance Attribute Summary
Attributes inherited from SQL::PlaceholderLiteralString
Class Method Summary collapse
-
.wrap(expr) ⇒ Object
Wrap the expression in a PGRowOp, without changing the SQL it would use.
Instance Method Summary collapse
-
#*(ce = (arg=false;nil)) ⇒ Object
Use the (identifier).* syntax to reference the members of the composite type as separate columns.
-
#[](member) ⇒ Object
Access a member of the composite type if given a symbol or an SQL::Identifier.
-
#splat(cast_to = nil) ⇒ Object
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.
Methods inherited from SQL::PlaceholderLiteralString
Methods included from HStoreOpMethods
Methods included from RangeOpMethods
Methods included from ArrayOpMethods
Methods included from JSONOpMethods
Methods included from InetOpMethods
Methods included from ExpressionMethods
Methods included from SQL::SubscriptMethods
Methods included from SQL::StringMethods
Methods included from SQL::PatternMatchMethods
Methods included from SQL::OrderMethods
Methods included from SQL::NumericMethods
Methods included from SQL::ComplexExpressionMethods
#extract, #sql_boolean, #sql_number, #sql_string
Methods included from SQL::CastMethods
#cast, #cast_numeric, #cast_string
Methods included from SQL::BooleanMethods
Methods included from SQL::AliasMethods
Methods inherited from SQL::Expression
#==, attr_reader, #eql?, #hash, inherited, #inspect, #lit, #sql_literal
Constructor Details
This class inherits a constructor from Sequel::SQL::PlaceholderLiteralString
Class Method Details
Instance Method Details
#*(ce = (arg=false;nil)) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/sequel/extensions/pg_row_ops.rb', line 124 def *(ce=(arg=false;nil)) if arg == false Sequel::SQL::ColumnAll.new([self]) else super(ce) end end |
#[](member) ⇒ Object
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.
108 109 110 111 112 113 114 115 |
# File 'lib/sequel/extensions/pg_row_ops.rb', line 108 def [](member) case member when Symbol, SQL::Identifier PGRowOp.new(QUALIFY, [self, member]) else PGRowOp.wrap(Sequel.pg_array_op(self)[member]) end end |
#splat(cast_to = nil) ⇒ Object
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
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/sequel/extensions/pg_row_ops.rb', line 143 def splat(cast_to=nil) if args.length > 1 raise Error, 'cannot splat a PGRowOp with multiple arguments' end if cast_to PGRowOp.new(ROW_CAST, args + [cast_to]) else PGRowOp.new(ROW, args) end end |