Class: Google::Cloud::Spanner::Project
- Inherits:
-
Object
- Object
- Google::Cloud::Spanner::Project
- Defined in:
- lib/google/cloud/spanner/project.rb
Overview
Project
Projects are top-level containers in Google Cloud Platform. They store information about billing and authorized users, and they contain Cloud Spanner data. Each project has a friendly name and a unique ID.
Google::Cloud::Spanner::Project is the main object for interacting with Cloud Spanner.
Instance and Database objects are created, accessed, and managed by Google::Cloud::Spanner::Project.
A Client obtained from a project can be used to read and/or modify data in a Cloud Spanner database.
See new and Google::Cloud#spanner.
Instance Method Summary collapse
-
#batch_client(instance_id, database_id, labels: nil, query_options: nil, directed_read_options: nil) ⇒ Client
Creates a Cloud Spanner batch client.
-
#client(instance_id, database_id, pool: {}, labels: nil, query_options: nil, database_role: nil, directed_read_options: nil) ⇒ Client
Creates a Cloud Spanner client.
-
#create_database(instance_id, database_id, statements: [], encryption_config: nil) ⇒ Database::Job
deprecated
Deprecated.
Use Admin::Database.database_admin.create_database instead.
-
#create_instance(instance_id, name: nil, config: nil, nodes: nil, processing_units: nil, labels: nil) ⇒ Instance::Job
deprecated
Deprecated.
Use Admin::Instance.instance_admin.create_instance instead.
-
#database(instance_id, database_id) ⇒ Google::Cloud::Spanner::Database?
deprecated
Deprecated.
Use Admin::Database.database_admin.get_database instead.
-
#databases(instance_id, token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Database>
deprecated
Deprecated.
Use Admin::Database.database_admin.list_databases instead.
-
#instance(instance_id) ⇒ Google::Cloud::Spanner::Instance?
deprecated
Deprecated.
Use Admin::Instance.instance_admin.get_instance instead.
-
#instance_config(instance_config_id) ⇒ Google::Cloud::Spanner::Instance::Config?
deprecated
Deprecated.
Use Admin::Instance.instance_admin.get_instance_config instead.
-
#instance_configs(token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Instance::Config>
deprecated
Deprecated.
Use Admin::Instance.instance_admin.list_instance_configs instead.
-
#instances(token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Instance>
deprecated
Deprecated.
Use Admin::Instance.instance_admin.list_instances instead.
-
#project_id ⇒ Object
(also: #project)
The identifier for the Cloud Spanner project.
Instance Method Details
#batch_client(instance_id, database_id, labels: nil, query_options: nil, directed_read_options: nil) ⇒ Client
Creates a Cloud Spanner batch client. A batch client is used to read data across multiple machines or processes.
The following settings can be provided:
:exclude_replicas
(Hash) Exclude_replicas indicates what replicas should be excluded from serving requests. Spanner will not route requests to the replicas in this list.:include_replicas
(Hash) Include_replicas indicates the order of replicas to process the request. If auto_failover_disabled is set to true and all replicas are exhausted without finding a healthy replica, Spanner will wait for a replica in the list to become available, requests may fail due to DEADLINE_EXCEEDED errors.
658 659 660 661 662 663 664 |
# File 'lib/google/cloud/spanner/project.rb', line 658 def batch_client instance_id, database_id, labels: nil, query_options: nil, directed_read_options: nil # Convert from possible Google::Protobuf::Map labels = labels.to_h { |k, v| [String(k), String(v)] } if labels BatchClient.new self, instance_id, database_id, session_labels: labels, query_options: , directed_read_options: end |
#client(instance_id, database_id, pool: {}, labels: nil, query_options: nil, database_role: nil, directed_read_options: nil) ⇒ Client
Creates a Cloud Spanner client. A client is used to read and/or modify data in a Cloud Spanner database.
The following settings can be provided:
:exclude_replicas
(Hash) Exclude_replicas indicates what replicas should be excluded from serving requests. Spanner will not route requests to the replicas in this list.:include_replicas
(Hash) Include_replicas indicates the order of replicas to process the request. If auto_failover_disabled is set to true and all replicas are exhausted without finding a healthy replica, Spanner will wait for a replica in the list to become available, requests may fail due to DEADLINE_EXCEEDED errors.
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/google/cloud/spanner/project.rb', line 566 def client instance_id, database_id, pool: {}, labels: nil, query_options: nil, database_role: nil, directed_read_options: nil # Convert from possible Google::Protobuf::Map labels = labels.to_h { |k, v| [String(k), String(v)] } if labels # Configs set by environment variables take over client-level configs. if .nil? = @query_options else = .merge @query_options unless @query_options.nil? end Client.new self, instance_id, database_id, session_labels: labels, pool_opts: (pool), query_options: , database_role: database_role, directed_read_options: end |
#create_database(instance_id, database_id, statements: [], encryption_config: nil) ⇒ Database::Job
Use Admin::Database.database_admin.create_database instead.
Creates a database and starts preparing it to begin serving.
See Database::Job.
475 476 477 478 479 480 481 |
# File 'lib/google/cloud/spanner/project.rb', line 475 def create_database instance_id, database_id, statements: [], encryption_config: nil grpc = service.create_database instance_id, database_id, statements: statements, encryption_config: encryption_config Database::Job.from_grpc grpc, service end |
#create_instance(instance_id, name: nil, config: nil, nodes: nil, processing_units: nil, labels: nil) ⇒ Instance::Job
Use Admin::Instance.instance_admin.create_instance instead.
Creates a Cloud Spanner instance and starts preparing it to begin serving.
See Instance::Job.
251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/google/cloud/spanner/project.rb', line 251 def create_instance instance_id, name: nil, config: nil, nodes: nil, processing_units: nil, labels: nil config = config.path if config.respond_to? :path # Convert from possible Google::Protobuf::Map labels = labels.to_h { |k, v| [String(k), String(v)] } if labels grpc = service.create_instance \ instance_id, name: name, config: config, nodes: nodes, processing_units: processing_units, labels: labels Instance::Job.from_grpc grpc, service end |
#database(instance_id, database_id) ⇒ Google::Cloud::Spanner::Database?
Use Admin::Database.database_admin.get_database instead.
Retrieves a database by unique identifier.
399 400 401 402 403 404 405 |
# File 'lib/google/cloud/spanner/project.rb', line 399 def database instance_id, database_id ensure_service! grpc = service.get_database instance_id, database_id Database.from_grpc grpc, service rescue Google::Cloud::NotFoundError nil end |
#databases(instance_id, token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Database>
Use Admin::Database.database_admin.list_databases instead.
Retrieves the list of databases for the project.
370 371 372 373 374 |
# File 'lib/google/cloud/spanner/project.rb', line 370 def databases instance_id, token: nil, max: nil ensure_service! grpc = service.list_databases instance_id, token: token, max: max Database::List.from_grpc grpc, service, instance_id, max end |
#instance(instance_id) ⇒ Google::Cloud::Spanner::Instance?
Use Admin::Instance.instance_admin.get_instance instead.
Retrieves a Cloud Spanner instance by unique identifier.
159 160 161 162 163 164 165 |
# File 'lib/google/cloud/spanner/project.rb', line 159 def instance instance_id ensure_service! grpc = service.get_instance instance_id Instance.from_grpc grpc, service rescue Google::Cloud::NotFoundError nil end |
#instance_config(instance_config_id) ⇒ Google::Cloud::Spanner::Instance::Config?
Use Admin::Instance.instance_admin.get_instance_config instead.
Retrieves an instance configuration by unique identifier.
328 329 330 331 332 333 334 |
# File 'lib/google/cloud/spanner/project.rb', line 328 def instance_config instance_config_id ensure_service! grpc = service.get_instance_config instance_config_id Instance::Config.from_grpc grpc rescue Google::Cloud::NotFoundError nil end |
#instance_configs(token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Instance::Config>
Use Admin::Instance.instance_admin.list_instance_configs instead.
Retrieves the list of instance configurations for the project.
297 298 299 300 301 |
# File 'lib/google/cloud/spanner/project.rb', line 297 def instance_configs token: nil, max: nil ensure_service! grpc = service.list_instance_configs token: token, max: max Instance::Config::List.from_grpc grpc, service, max end |
#instances(token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Instance>
Use Admin::Instance.instance_admin.list_instances instead.
Retrieves the list of Cloud Spanner instances for the project.
131 132 133 134 135 |
# File 'lib/google/cloud/spanner/project.rb', line 131 def instances token: nil, max: nil ensure_service! grpc = service.list_instances token: token, max: max Instance::List.from_grpc grpc, service, max end |
#project_id ⇒ Object Also known as: project
The identifier for the Cloud Spanner project.
93 94 95 |
# File 'lib/google/cloud/spanner/project.rb', line 93 def project_id service.project end |