Method: Azure::Table::TableService#query_entities

Defined in:
lib/azure/table/table_service.rb

#query_entities(table_name, options = {}) ⇒ Object

Public: Queries entities for the given table name

Attributes

  • table_name - String. The table name

  • options - Hash. Optional parameters.

Options

Accepted key/value pairs in options parameter are:

  • :partition_key - String. The partition key (optional)

  • :row_key - String. The row key (optional)

  • :select - Array. An array of property names to return (optional)

  • :filter - String. A filter expression (optional)

  • :top - Integer. A limit for the number of results returned (optional)

  • :continuation_token - Hash. The continuation token.

  • :timeout - Integer. A timeout in seconds.

See msdn.microsoft.com/en-us/library/azure/dd179421

Returns an array with an extra continuation_token property on success



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/azure/table/table_service.rb', line 243

def query_entities(table_name, options={})
  query ={}
  query["$select"] = options[:select].join ',' if options[:select]
  query["$filter"] = options[:filter] if options[:filter]
  query["$top"] = options[:top].to_s if options[:top] unless options[:partition_key] and options[:row_key]
  query["NextPartitionKey"] = options[:continuation_token][:next_partition_key] if options[:continuation_token] and options[:continuation_token][:next_partition_key]
  query["NextRowKey"] = options[:continuation_token][:next_row_key] if options[:continuation_token] and options[:continuation_token][:next_row_key]
  query["timeout"] = options[:timeout].to_s if options[:timeout]

  uri = entities_uri(table_name, options[:partition_key], options[:row_key], query)
  response = call(:get, uri, nil, { "DataServiceVersion" => "2.0;NetFx"})

  entities = Azure::Service::EnumerationResults.new

  results = (options[:partition_key] and options[:row_key]) ? [Azure::Table::Serialization.hash_from_entry_xml(response.body)] : Azure::Table::Serialization.entries_from_feed_xml(response.body)

  results.each do |result|
    entity = Entity.new do |e|
      e.table = table_name
      e.updated = result[:updated]
      e.etag = response.headers["etag"] || result[:etag]
      e.properties = result[:properties]
    end
    entities.push entity
  end if results

  entities.continuation_token = nil
  entities.continuation_token = {
    :next_partition_key=> response.headers["x-ms-continuation-NextPartitionKey"],
    :next_row_key => response.headers["x-ms-continuation-NextRowKey"]
    } if response.headers["x-ms-continuation-NextPartitionKey"]

  entities
end