Class: Azure::Table::Query

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table = "", partition = nil, row = nil, &block) ⇒ Query

Returns a new instance of Query.



21
22
23
24
25
26
27
28
29
30
# File 'lib/azure/table/query.rb', line 21

def initialize(table="", partition=nil, row=nil, &block)
  @table = table
  @partition_key = partition
  @row_key = row
  @fields = []
  @filters = []
  @top_n = nil
  @table_service = Azure::Table::TableService.new
  self.instance_eval(&block) if block_given?
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



36
37
38
# File 'lib/azure/table/query.rb', line 36

def fields
  @fields
end

#filtersObject (readonly)

Returns the value of attribute filters.



37
38
39
# File 'lib/azure/table/query.rb', line 37

def filters
  @filters
end

#next_partition_keyObject (readonly)

Returns the value of attribute next_partition_key.



40
41
42
# File 'lib/azure/table/query.rb', line 40

def next_partition_key
  @next_partition_key
end

#next_row_keyObject (readonly)

Returns the value of attribute next_row_key.



41
42
43
# File 'lib/azure/table/query.rb', line 41

def next_row_key
  @next_row_key
end

#partition_keyObject (readonly)

Returns the value of attribute partition_key.



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

def partition_key
  @partition_key
end

#row_keyObject (readonly)

Returns the value of attribute row_key.



34
35
36
# File 'lib/azure/table/query.rb', line 34

def row_key
  @row_key
end

#tableObject (readonly)

Returns the value of attribute table.



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

def table
  @table
end

#table_serviceObject (readonly)

Returns the value of attribute table_service.



43
44
45
# File 'lib/azure/table/query.rb', line 43

def table_service
  @table_service
end

#top_nObject (readonly)

Returns the value of attribute top_n.



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

def top_n
  @top_n
end

Instance Method Details

#_build_filter_stringObject



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/azure/table/query.rb', line 99

def _build_filter_string
  result = ""
  clauses = []
  filters.each { |f|
    clauses.push "#{f[0].to_s} #{f[1].to_s} #{Azure::Table::EdmType.serialize_query_value(f[2])}"
  }
  return nil if clauses.length == 0 
  
  result << clauses.join(" and ")
  result
end

#executeObject



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/azure/table/query.rb', line 85

def execute
  @table_service.query_entities(@table, {
    :partition_key => @partition_key,
    :row_key => @row_key, 
    :select => @fields.map{ |f| f.to_s },
    :filter => _build_filter_string,
    :top => (@top_n ? @top_n.to_i : @top_n),
    :continuation_token => { 
      :next_partition_key => @next_partition_key,
      :next_row_key => @next_row_key
    }
  })
end

#from(table_name) ⇒ Object



45
46
47
48
# File 'lib/azure/table/query.rb', line 45

def from(table_name)
  @table = table_name
  self
end

#next_partition(next_partition_key) ⇒ Object



75
76
77
78
# File 'lib/azure/table/query.rb', line 75

def next_partition(next_partition_key)
  @next_partition_key = next_partition_key
  self
end

#next_row(next_row_key) ⇒ Object



80
81
82
83
# File 'lib/azure/table/query.rb', line 80

def next_row(next_row_key)
  @next_row_key = next_row_key
  self
end

#partition(partition_key) ⇒ Object



50
51
52
53
# File 'lib/azure/table/query.rb', line 50

def partition(partition_key)
  @partition_key = partition_key
  self
end

#row(row_key) ⇒ Object



55
56
57
58
# File 'lib/azure/table/query.rb', line 55

def row(row_key)
  @row_key = row_key
  self
end

#select(*p) ⇒ Object



60
61
62
63
# File 'lib/azure/table/query.rb', line 60

def select(*p)
  @fields.concat(p)
  self
end

#top(n) ⇒ Object



70
71
72
73
# File 'lib/azure/table/query.rb', line 70

def top(n)
  @top_n = n
  self
end

#where(*p) ⇒ Object



65
66
67
68
# File 'lib/azure/table/query.rb', line 65

def where(*p)
  @filters.push(p)
  self
end