class Azure::Storage::Table::Query

Attributes

fields[R]
filters[R]
next_partition_key[R]
next_row_key[R]
partition_key[R]
row_key[R]
table[R]
table_service[R]
top_n[R]

Public Class Methods

new(table = "", partition = nil, row = nil, &block) click to toggle source
# 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

Public Instance Methods

_build_filter_string() click to toggle source
# 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
execute() click to toggle source
# 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) click to toggle source
# File lib/azure/storage/table/query.rb, line 53
def from(table_name)
  @table = table_name
  self
end
next_partition(next_partition_key) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/azure/storage/table/query.rb, line 58
def partition(partition_key)
  @partition_key = partition_key
  self
end
row(row_key) click to toggle source
# File lib/azure/storage/table/query.rb, line 63
def row(row_key)
  @row_key = row_key
  self
end
select(*p) click to toggle source
# File lib/azure/storage/table/query.rb, line 68
def select(*p)
  @fields.concat(p)
  self
end
top(n) click to toggle source
# File lib/azure/storage/table/query.rb, line 78
def top(n)
  @top_n = n
  self
end
where(*p) click to toggle source
# File lib/azure/storage/table/query.rb, line 73
def where(*p)
  @filters.push(p)
  self
end