Class: ConceptQL::Nodes::Count

Inherits:
PassThru show all
Defined in:
lib/conceptql/nodes/count.rb

Constant Summary

Constants inherited from Node

Node::COLUMNS

Instance Attribute Summary

Attributes inherited from Node

#values

Instance Method Summary collapse

Methods inherited from PassThru

#types

Methods inherited from Node

#arguments, #children, #columns, #evaluate, #initialize, #select_it, #sql, #stream, #types

Constructor Details

This class inherits a constructor from ConceptQL::Nodes::Node

Instance Method Details

#query(db) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/conceptql/nodes/count.rb', line 6

def query(db)
  db.from(unioned(db))
    .group(*COLUMNS)
    .select(*(COLUMNS - [:value_as_numeric]))
    .select_append{count(1).as(:value_as_numeric)}
    .from_self
end

#unioned(db) ⇒ Object



14
15
16
17
18
# File 'lib/conceptql/nodes/count.rb', line 14

def unioned(db)
  children.map { |c| c.evaluate(db) }.inject do |uni, q|
    uni.union(q)
  end
end