Class: Virsandra::Query

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rowObject (readonly)

Returns the value of attribute row


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

def row
  @row
end

#statementObject

Returns the value of attribute statement


7
8
9
# File 'lib/virsandra/query.rb', line 7

def statement
  @statement
end

#table=(value) ⇒ Object

Sets the attribute table

Parameters:

  • value

    the value to set the attribute table to.


7
8
9
# File 'lib/virsandra/query.rb', line 7

def table=(value)
  @table = value
end

Class Method Details

.alterObject


23
24
25
# File 'lib/virsandra/query.rb', line 23

def alter
  AlterQuery.new
end

.deleteObject


19
20
21
# File 'lib/virsandra/query.rb', line 19

def delete
  DeleteQuery.new
end

.insertObject


15
16
17
# File 'lib/virsandra/query.rb', line 15

def insert
  InsertQuery.new
end

.select(*fields) ⇒ Object


11
12
13
# File 'lib/virsandra/query.rb', line 11

def select(*fields)
  SelectQuery.new(fields)
end

Instance Method Details

#add(*args) ⇒ Object

Raises:


50
51
52
# File 'lib/virsandra/query.rb', line 50

def add *args
  raise InvalidQuery.new("Add clause not defined for #{self.class}")
end

#executeObject


58
59
60
61
# File 'lib/virsandra/query.rb', line 58

def execute

  @row = Virsandra.execute(self.to_s)
end

#fetch(statement = nil) ⇒ Object


63
64
65
66
67
# File 'lib/virsandra/query.rb', line 63

def fetch(statement = nil)
  @raw_query = statement if statement
  execute
  fetch_with_symbolized_keys
end

#from(*args) ⇒ Object Also known as: table, into

Raises:


32
33
34
# File 'lib/virsandra/query.rb', line 32

def from *args
  raise InvalidQuery.new("From, table or into clause not defined for #{self.class}")
end

#limit(*args) ⇒ Object

Raises:


46
47
48
# File 'lib/virsandra/query.rb', line 46

def limit *args
  raise InvalidQuery.new("Limit clause not defined for #{self.class}")
end

#order(*args) ⇒ Object

Raises:


42
43
44
# File 'lib/virsandra/query.rb', line 42

def order *args
  raise InvalidQuery.new("Order clause not defined for #{self.class}")
end

#to_sObject


28
29
30
# File 'lib/virsandra/query.rb', line 28

def to_s
  raw_query.map{|query_part| query_part.to_s }.reject(&:empty?).join(" ")
end

#values(*args) ⇒ Object

Raises:


54
55
56
# File 'lib/virsandra/query.rb', line 54

def values *args
  raise InvalidQuery.new("Values clause not defined for #{self.class}")
end

#where(*args) ⇒ Object

Raises:


38
39
40
# File 'lib/virsandra/query.rb', line 38

def where *args
  raise InvalidQuery.new("Where clause not defined for #{self.class}")
end