Class: Google::Cloud::Datastore::V1::Datastore::Client
- Inherits:
-
Object
- Object
- Google::Cloud::Datastore::V1::Datastore::Client
- Defined in:
- lib/google/cloud/datastore/v1/datastore/client.rb
Overview
Client for the Datastore service.
Each RPC normalizes the partition IDs of the keys in its input entities, and always returns entities with keys with normalized partition IDs. This applies to all keys and entities, including those in values, except keys with both an empty path and an empty or unset partition ID. Normalization of input keys sets the project ID (if not already set) to the project ID from the request.
Defined Under Namespace
Classes: Configuration
Class Method Summary collapse
-
.configure {|config| ... } ⇒ Client::Configuration
Configure the Datastore Client class.
Instance Method Summary collapse
-
#allocate_ids(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Datastore::V1::AllocateIdsResponse
Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.
-
#begin_transaction(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Datastore::V1::BeginTransactionResponse
Begins a new transaction.
-
#commit(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Datastore::V1::CommitResponse
Commits a transaction, optionally creating, deleting or modifying some entities.
-
#configure {|config| ... } ⇒ Client::Configuration
Configure the Datastore Client instance.
-
#initialize {|config| ... } ⇒ Client
constructor
Create a new Datastore client object.
-
#lookup(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Datastore::V1::LookupResponse
Looks up entities by key.
-
#reserve_ids(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Datastore::V1::ReserveIdsResponse
Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.
-
#rollback(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Datastore::V1::RollbackResponse
Rolls back a transaction.
-
#run_aggregation_query(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Datastore::V1::RunAggregationQueryResponse
Runs an aggregation query.
-
#run_query(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Datastore::V1::RunQueryResponse
Queries for entities.
-
#universe_domain ⇒ String
The effective universe domain.
Constructor Details
#initialize {|config| ... } ⇒ Client
Create a new Datastore client object.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 152 def initialize # These require statements are intentionally placed here to initialize # the gRPC module only when it's required. # See https://github.com/googleapis/toolkit/issues/446 require "gapic/grpc" require "google/datastore/v1/datastore_services_pb" # Create the configuration object @config = Configuration.new Client.configure # Yield the configuration if needed yield @config if block_given? # Create credentials credentials = @config.credentials # Use self-signed JWT if the endpoint is unchanged from default, # but only if the default endpoint does not have a region prefix. enable_self_signed_jwt = @config.endpoint.nil? || (@config.endpoint == Configuration::DEFAULT_ENDPOINT && !@config.endpoint.split(".").first.include?("-")) credentials ||= Credentials.default scope: @config.scope, enable_self_signed_jwt: enable_self_signed_jwt if credentials.is_a?(::String) || credentials.is_a?(::Hash) credentials = Credentials.new credentials, scope: @config.scope end @quota_project_id = @config.quota_project @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id @datastore_stub = ::Gapic::ServiceStub.new( ::Google::Cloud::Datastore::V1::Datastore::Stub, credentials: credentials, endpoint: @config.endpoint, endpoint_template: DEFAULT_ENDPOINT_TEMPLATE, universe_domain: @config.universe_domain, channel_args: @config.channel_args, interceptors: @config.interceptors, channel_pool_config: @config.channel_pool ) end |
Class Method Details
.configure {|config| ... } ⇒ Client::Configuration
Configure the Datastore Client class.
See Configuration for a description of the configuration fields.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 62 def self.configure @configure ||= begin namespace = ["Google", "Cloud", "Datastore", "V1"] parent_config = while namespace.any? parent_name = namespace.join "::" parent_const = const_get parent_name break parent_const.configure if parent_const.respond_to? :configure namespace.pop end default_config = Client::Configuration.new parent_config default_config.rpcs.lookup.timeout = 60.0 default_config.rpcs.lookup.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4] } default_config.rpcs.run_query.timeout = 60.0 default_config.rpcs.run_query.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4] } default_config.rpcs.run_aggregation_query.timeout = 60.0 default_config.rpcs.run_aggregation_query.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4] } default_config.rpcs.begin_transaction.timeout = 60.0 default_config.rpcs.commit.timeout = 60.0 default_config.rpcs.rollback.timeout = 60.0 default_config.rpcs.allocate_ids.timeout = 60.0 default_config.rpcs.reserve_ids.timeout = 60.0 default_config.rpcs.reserve_ids.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4] } default_config end yield @configure if block_given? @configure end |
Instance Method Details
#allocate_ids(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::AllocateIdsResponse #allocate_ids(project_id: nil, database_id: nil, keys: nil) ⇒ ::Google::Cloud::Datastore::V1::AllocateIdsResponse
Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 868 def allocate_ids request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::AllocateIdsRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.allocate_ids..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Datastore::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.project_id && !request.project_id.empty? header_params["project_id"] = request.project_id end if request.database_id && !request.database_id.empty? header_params["database_id"] = request.database_id end request_params_header = URI.encode_www_form header_params [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.allocate_ids.timeout, metadata: , retry_policy: @config.rpcs.allocate_ids.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @datastore_stub.call_rpc :allocate_ids, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#begin_transaction(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::BeginTransactionResponse #begin_transaction(project_id: nil, database_id: nil, transaction_options: nil) ⇒ ::Google::Cloud::Datastore::V1::BeginTransactionResponse
Begins a new transaction.
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 556 def begin_transaction request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::BeginTransactionRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.begin_transaction..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Datastore::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.project_id && !request.project_id.empty? header_params["project_id"] = request.project_id end if request.database_id && !request.database_id.empty? header_params["database_id"] = request.database_id end request_params_header = URI.encode_www_form header_params [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.begin_transaction.timeout, metadata: , retry_policy: @config.rpcs.begin_transaction.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @datastore_stub.call_rpc :begin_transaction, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#commit(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::CommitResponse #commit(project_id: nil, database_id: nil, mode: nil, transaction: nil, single_use_transaction: nil, mutations: nil) ⇒ ::Google::Cloud::Datastore::V1::CommitResponse
Commits a transaction, optionally creating, deleting or modifying some entities.
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 675 def commit request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::CommitRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.commit..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Datastore::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.project_id && !request.project_id.empty? header_params["project_id"] = request.project_id end if request.database_id && !request.database_id.empty? header_params["database_id"] = request.database_id end request_params_header = URI.encode_www_form header_params [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.commit.timeout, metadata: , retry_policy: @config.rpcs.commit.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @datastore_stub.call_rpc :commit, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#configure {|config| ... } ⇒ Client::Configuration
Configure the Datastore Client instance.
The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on configure.
See Configuration for a description of the configuration fields.
122 123 124 125 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 122 def configure yield @config if block_given? @config end |
#lookup(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::LookupResponse #lookup(project_id: nil, database_id: nil, read_options: nil, keys: nil) ⇒ ::Google::Cloud::Datastore::V1::LookupResponse
Looks up entities by key.
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 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 247 def lookup request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::LookupRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.lookup..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Datastore::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.project_id && !request.project_id.empty? header_params["project_id"] = request.project_id end if request.database_id && !request.database_id.empty? header_params["database_id"] = request.database_id end request_params_header = URI.encode_www_form header_params [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.lookup.timeout, metadata: , retry_policy: @config.rpcs.lookup.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @datastore_stub.call_rpc :lookup, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#reserve_ids(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::ReserveIdsResponse #reserve_ids(project_id: nil, database_id: nil, keys: nil) ⇒ ::Google::Cloud::Datastore::V1::ReserveIdsResponse
Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 965 def reserve_ids request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::ReserveIdsRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.reserve_ids..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Datastore::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.project_id && !request.project_id.empty? header_params["project_id"] = request.project_id end if request.database_id && !request.database_id.empty? header_params["database_id"] = request.database_id end request_params_header = URI.encode_www_form header_params [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.reserve_ids.timeout, metadata: , retry_policy: @config.rpcs.reserve_ids.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @datastore_stub.call_rpc :reserve_ids, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#rollback(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::RollbackResponse #rollback(project_id: nil, database_id: nil, transaction: nil) ⇒ ::Google::Cloud::Datastore::V1::RollbackResponse
Rolls back a transaction.
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 771 def rollback request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RollbackRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.rollback..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Datastore::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.project_id && !request.project_id.empty? header_params["project_id"] = request.project_id end if request.database_id && !request.database_id.empty? header_params["database_id"] = request.database_id end request_params_header = URI.encode_www_form header_params [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.rollback.timeout, metadata: , retry_policy: @config.rpcs.rollback.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @datastore_stub.call_rpc :rollback, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#run_aggregation_query(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::RunAggregationQueryResponse #run_aggregation_query(project_id: nil, database_id: nil, partition_id: nil, read_options: nil, aggregation_query: nil, gql_query: nil, explain_options: nil) ⇒ ::Google::Cloud::Datastore::V1::RunAggregationQueryResponse
Runs an aggregation query.
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 461 def run_aggregation_query request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RunAggregationQueryRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.run_aggregation_query..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Datastore::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.project_id && !request.project_id.empty? header_params["project_id"] = request.project_id end if request.database_id && !request.database_id.empty? header_params["database_id"] = request.database_id end request_params_header = URI.encode_www_form header_params [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.run_aggregation_query.timeout, metadata: , retry_policy: @config.rpcs.run_aggregation_query.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @datastore_stub.call_rpc :run_aggregation_query, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#run_query(request, options = nil) ⇒ ::Google::Cloud::Datastore::V1::RunQueryResponse #run_query(project_id: nil, database_id: nil, partition_id: nil, read_options: nil, query: nil, gql_query: nil, explain_options: nil) ⇒ ::Google::Cloud::Datastore::V1::RunQueryResponse
Queries for entities.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 354 def run_query request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RunQueryRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.run_query..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Datastore::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.project_id && !request.project_id.empty? header_params["project_id"] = request.project_id end if request.database_id && !request.database_id.empty? header_params["database_id"] = request.database_id end request_params_header = URI.encode_www_form header_params [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.run_query.timeout, metadata: , retry_policy: @config.rpcs.run_query.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @datastore_stub.call_rpc :run_query, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#universe_domain ⇒ String
The effective universe domain
132 133 134 |
# File 'lib/google/cloud/datastore/v1/datastore/client.rb', line 132 def universe_domain @datastore_stub.universe_domain end |