Class: Azure::Storage::Table::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/azure/storage/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.


29
30
31
32
33
34
35
36
37
38
# File 'lib/azure/storage/table/query.rb', line 29

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

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.


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

def fields
  @fields
end

#filtersObject (readonly)

Returns the value of attribute filters.


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

def filters
  @filters
end

#next_partition_keyObject (readonly)

Returns the value of attribute next_partition_key.


48
49
50
# File 'lib/azure/storage/table/query.rb', line 48

def next_partition_key
  @next_partition_key
end

#next_row_keyObject (readonly)

Returns the value of attribute next_row_key.


49
50
51
# File 'lib/azure/storage/table/query.rb', line 49

def next_row_key
  @next_row_key
end

#partition_keyObject (readonly)

Returns the value of attribute partition_key.


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

def partition_key
  @partition_key
end

#row_keyObject (readonly)

Returns the value of attribute row_key.


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

def row_key
  @row_key
end

#tableObject (readonly)

Returns the value of attribute table.


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

def table
  @table
end

#table_serviceObject (readonly)

Returns the value of attribute table_service.


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

def table_service
  @table_service
end

#top_nObject (readonly)

Returns the value of attribute top_n.


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

def top_n
  @top_n
end

Instance Method Details

#_build_filter_stringObject


105
106
107
108
109
110
111
112
113
114
115
# File 'lib/azure/storage/table/query.rb', line 105

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

  result << clauses.join(" and ")
  result
end

#executeObject


93
94
95
96
97
98
99
100
101
102
103
# File 'lib/azure/storage/table/query.rb', line 93

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


53
54
55
56
# File 'lib/azure/storage/table/query.rb', line 53

def from(table_name)
  @table = table_name
  self
end

#next_partition(next_partition_key) ⇒ Object


83
84
85
86
# File 'lib/azure/storage/table/query.rb', line 83

def next_partition(next_partition_key)
  @next_partition_key = next_partition_key
  self
end

#next_row(next_row_key) ⇒ Object


88
89
90
91
# File 'lib/azure/storage/table/query.rb', line 88

def next_row(next_row_key)
  @next_row_key = next_row_key
  self
end

#partition(partition_key) ⇒ Object


58
59
60
61
# File 'lib/azure/storage/table/query.rb', line 58

def partition(partition_key)
  @partition_key = partition_key
  self
end

#row(row_key) ⇒ Object


63
64
65
66
# File 'lib/azure/storage/table/query.rb', line 63

def row(row_key)
  @row_key = row_key
  self
end

#select(*p) ⇒ Object


68
69
70
71
# File 'lib/azure/storage/table/query.rb', line 68

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

#top(n) ⇒ Object


78
79
80
81
# File 'lib/azure/storage/table/query.rb', line 78

def top(n)
  @top_n = n
  self
end

#where(*p) ⇒ Object


73
74
75
76
# File 'lib/azure/storage/table/query.rb', line 73

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