Module: SQLiterate::Node::Query

Defined in:
lib/sqliterate/node/control/query.rb

Instance Method Summary collapse

Instance Method Details

#common_tablesObject



4
5
6
# File 'lib/sqliterate/node/control/query.rb', line 4

def common_tables
  Hash[ with_section.tables.map { |t| [t.first, expand_table(t)] } ]
end

#expand_table(t) ⇒ Object



15
16
17
18
# File 'lib/sqliterate/node/control/query.rb', line 15

def expand_table(t)
  a, b = t
  b ? b.flat_map { |x| expand_table(x) } : [a]
end

#tablesObject



8
9
10
11
12
13
# File 'lib/sqliterate/node/control/query.rb', line 8

def tables
  cte = common_tables
  query_expression.tables.flat_map { |t| expand_table(t) }
                         .flat_map { |t| cte[t] || [t] }
                         .sort.uniq
end