Class: AzureDocumentDB::PartitionedCollectionClient
- Defined in:
- lib/embulk/output/documentdb/partitioned_coll_client.rb
Instance Method Summary collapse
- #create_collection(database_resource, collection_name, partition_key_paths, offer_throughput = AzureDocumentDB::PARTITIONED_COLL_MIN_THROUGHPUT) ⇒ Object
- #create_document(collection_resource, document_id, document, partitioned_key) ⇒ Object
- #find_documents(collection_resource, document_id, partitioned_key, partitioned_key_value, custom_headers = {}) ⇒ Object
Methods inherited from Client
#create_database, #find_collections_by_name, #find_databases_by_name, #get_collection_resource, #get_database_resource, #initialize, #query_documents
Constructor Details
This class inherits a constructor from AzureDocumentDB::Client
Instance Method Details
#create_collection(database_resource, collection_name, partition_key_paths, offer_throughput = AzureDocumentDB::PARTITIONED_COLL_MIN_THROUGHPUT) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/embulk/output/documentdb/partitioned_coll_client.rb', line 11 def create_collection(database_resource, collection_name, partition_key_paths, offer_throughput = AzureDocumentDB::PARTITIONED_COLL_MIN_THROUGHPUT ) if (offer_throughput < AzureDocumentDB::PARTITIONED_COLL_MIN_THROUGHPUT) raise ArgumentError.new sprintf("Offeer thoughput need to be more than %d !", AzureDocumentDB::PARTITIONED_COLL_MIN_THROUGHPUT) end if (partition_key_paths.length < 1 ) raise ArgumentError.new "No PartitionKey paths!" end = { 'indexingPolicy' => { 'indexingMode' => "consistent", 'automatic'=>true }, 'partitionKey' => { "paths" => partition_key_paths, "kind" => "Hash" } } custom_headers= {'x-ms-offer-throughput' => offer_throughput } super(database_resource, collection_name, , custom_headers) end |
#create_document(collection_resource, document_id, document, partitioned_key) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/embulk/output/documentdb/partitioned_coll_client.rb', line 30 def create_document(collection_resource, document_id, document, partitioned_key ) if partitioned_key.empty? raise ArgumentError.new "No partitioned key!" end if !document.key?(partitioned_key) raise ArgumentError.new "No partitioned key in your document!" end partitioned_key_value = document[partitioned_key] custom_headers = { 'x-ms-documentdb-partitionkey' => "[\"#{partitioned_key_value}\"]" } super(collection_resource, document_id, document, custom_headers) end |
#find_documents(collection_resource, document_id, partitioned_key, partitioned_key_value, custom_headers = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/embulk/output/documentdb/partitioned_coll_client.rb', line 44 def find_documents(collection_resource, document_id, partitioned_key, partitioned_key_value, custom_headers={}) if !collection_resource raise ArgumentError.new "No collection_resource!" end ret = {} query_params = [] query_text = sprintf("SELECT * FROM c WHERE c.id=@id AND c.%s=@value", partitioned_key) query_params.push( {:name=>"@id", :value=> document_id } ) query_params.push( {:name=>"@value", :value=> partitioned_key_value } ) url = sprintf("%s/dbs/%s/colls/%s/docs", @url_endpoint, collection_resource.database_rid, collection_resource.collection_rid) ret = query(AzureDocumentDB::RESOURCE_TYPE_DOCUMENT, collection_resource.collection_rid, url, query_text, query_params, custom_headers) ret end |