Class: ConceptQL::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/conceptql/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, statement, tree = Tree.new) ⇒ Query

Returns a new instance of Query.



7
8
9
10
11
# File 'lib/conceptql/query.rb', line 7

def initialize(db, statement, tree = Tree.new)
  @db = db
  @statement = statement
  @tree = tree
end

Instance Attribute Details

#statementObject (readonly)

Returns the value of attribute statement.



6
7
8
# File 'lib/conceptql/query.rb', line 6

def statement
  @statement
end

Instance Method Details

#executeObject

To avoid a performance penalty, only execute the last SQL statement in an array of ConceptQL statements so that define’s “create_table” SQL isn’t executed twice



29
30
31
# File 'lib/conceptql/query.rb', line 29

def execute
  query.all
end

#queriesObject



13
14
15
# File 'lib/conceptql/query.rb', line 13

def queries
  build_query(db)
end

#queryObject



17
18
19
# File 'lib/conceptql/query.rb', line 17

def query
  queries.last
end

#sqlObject



21
22
23
24
# File 'lib/conceptql/query.rb', line 21

def sql
  tree.opts[:sql_only] = true
  nodes.map { |node| node.sql(db) }.join(";\n") + ';'
end

#typesObject



33
34
35
# File 'lib/conceptql/query.rb', line 33

def types
  tree.root(self).last.types
end