Class: Torque::PostgreSQL::Arel::Nodes::FromItem
- Inherits:
-
Arel::Nodes::Binary
- Object
- Arel::Nodes::Binary
- Torque::PostgreSQL::Arel::Nodes::FromItem
- Defined in:
- lib/torque/postgresql/arel/nodes.rb,
sig/torque/postgresql/arel/nodes.rbs
Overview
An aliased FROM item. definitions maps a column name to the SQL
type a function has to be told to return, columns are the plain
names the alias exposes, ordinality names the appended counter,
and lateral is only needed when the source is a subquery
Instance Attribute Summary collapse
-
#columns ⇒ Array[column_ref]?
readonly
Returns the value of attribute columns.
-
#definitions ⇒ Hash[column_ref, String?]?
readonly
Returns the value of attribute definitions.
-
#lateral ⇒ Boolean
readonly
Returns the value of attribute lateral.
-
#ordinality ⇒ String?
readonly
Returns the value of attribute ordinality.
Instance Method Summary collapse
-
#alias_columns ⇒ Hash[column_ref, String?]
What the alias exposes, as name => type, where a
niltype means the name stands on its own. -
#initialize(source, name, columns: nil, definitions: nil, ordinality: nil, lateral: false) ⇒ FromItem
constructor
A new instance of FromItem.
-
#rows_from? ⇒ Boolean
The definitions can only be moved into the source when the counter forces the
ROWS FROMform, since PostgreSQL refuses a column definition list next toWITH ORDINALITY.
Constructor Details
#initialize(source, name, columns: nil, definitions: nil, ordinality: nil, lateral: false) ⇒ FromItem
Returns a new instance of FromItem.
101 102 103 104 105 106 107 108 |
# File 'lib/torque/postgresql/arel/nodes.rb', line 101 def initialize(source, name, columns: nil, definitions: nil, ordinality: nil, lateral: false) @columns = Array.wrap(columns).presence&.freeze @definitions = definitions.presence&.freeze @ordinality = ordinality&.to_s @lateral = lateral super(source, name.to_s) end |
Instance Attribute Details
#columns ⇒ Array[column_ref]? (readonly)
Returns the value of attribute columns.
97 98 99 |
# File 'lib/torque/postgresql/arel/nodes.rb', line 97 def columns @columns end |
#definitions ⇒ Hash[column_ref, String?]? (readonly)
Returns the value of attribute definitions.
97 98 99 |
# File 'lib/torque/postgresql/arel/nodes.rb', line 97 def definitions @definitions end |
#lateral ⇒ Boolean (readonly)
Returns the value of attribute lateral.
97 98 99 |
# File 'lib/torque/postgresql/arel/nodes.rb', line 97 def lateral @lateral end |
#ordinality ⇒ String? (readonly)
Returns the value of attribute ordinality.
97 98 99 |
# File 'lib/torque/postgresql/arel/nodes.rb', line 97 def ordinality @ordinality end |
Instance Method Details
#alias_columns ⇒ Hash[column_ref, String?]
What the alias exposes, as name => type, where a nil type means
the name stands on its own. Types are only spelled out here when
they have not been moved into the ROWS FROM source.
The list is all or nothing, because PostgreSQL matches it positionally: a partial list silently renames the columns it does reach instead of naming the ones it does not
124 125 126 127 128 129 130 131 132 |
# File 'lib/torque/postgresql/arel/nodes.rb', line 124 def alias_columns return {} if columns.nil? && definitions.nil? plain = rows_from? ? definitions.keys : columns result = plain.nil? ? definitions : plain.to_h { |name| [name.to_s, nil] } return result if ordinality.blank? result.merge(ordinality => nil) end |
#rows_from? ⇒ Boolean
The definitions can only be moved into the source when the counter
forces the ROWS FROM form, since PostgreSQL refuses a column
definition list next to WITH ORDINALITY
113 114 115 |
# File 'lib/torque/postgresql/arel/nodes.rb', line 113 def rows_from? ordinality.present? && definitions.present? end |