Module: Sequel::MSSQL::EmulateLateralWithApply
- Defined in:
- lib/sequel/extensions/mssql_emulate_lateral_with_apply.rb
Instance Method Summary collapse
-
#from(*source, &block) ⇒ Object
When a FROM entry uses a LATERAL subquery, convert that entry into a CROSS APPLY.
-
#join_table(type, table, expr = nil) ⇒ Object
If the table is a dataset that uses LATERAL, convert it to a CROSS APPLY if it is a INNER or CROSS JOIN, and an OUTER APPLY if it is a LEFT JOIN.
-
#supports_lateral_subqueries? ⇒ Boolean
MSSQL can emulate lateral subqueries via CROSS/OUTER APPLY when using this extension.
Instance Method Details
#from(*source, &block) ⇒ Object
When a FROM entry uses a LATERAL subquery, convert that entry into a CROSS APPLY.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sequel/extensions/mssql_emulate_lateral_with_apply.rb', line 54 def from(*source, &block) virtual_row_columns(source, block) lateral, source = source.partition{|t| t.is_a?(Sequel::Dataset) && t.opts[:lateral] || (t.is_a?(Sequel::SQL::AliasedExpression) && t.expression.is_a?(Sequel::Dataset) && t.expression.opts[:lateral])} unless source.empty? return super(*source, &nil) if !lateral || lateral.empty? ds = from(*source) lateral.each do |l| l = if l.is_a?(Sequel::SQL::AliasedExpression) l.expression.clone(:lateral=>nil).as(l.alias) else l.clone(:lateral=>nil) end ds = ds.cross_apply(l) end ds end |
#join_table(type, table, expr = nil) ⇒ Object
If the table is a dataset that uses LATERAL, convert it to a CROSS APPLY if it is a INNER or CROSS JOIN, and an OUTER APPLY if it is a LEFT JOIN.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sequel/extensions/mssql_emulate_lateral_with_apply.rb', line 33 def join_table(type, table, expr=nil, *) if table.is_a?(Dataset) && table.opts[:lateral] table = table.clone(:lateral=>nil) case type when :inner type = :cross_apply table = table.where(expr) expr = nil when :cross type = :cross_apply when :left, :left_outer type = :outer_apply table = table.where(expr) expr = nil end end super end |
#supports_lateral_subqueries? ⇒ Boolean
MSSQL can emulate lateral subqueries via CROSS/OUTER APPLY when using this extension.
73 74 75 |
# File 'lib/sequel/extensions/mssql_emulate_lateral_with_apply.rb', line 73 def supports_lateral_subqueries? true end |