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) ⇒ Client
Creates a Cloud Spanner batch client.
-
#client(instance_id, database_id, pool: {}, labels: nil, query_options: nil) ⇒ Client
Creates a Cloud Spanner client.
-
#create_database(instance_id, database_id, statements: [], encryption_config: nil) ⇒ Database::Job
Creates a database and starts preparing it to begin serving.
-
#create_instance(instance_id, name: nil, config: nil, nodes: nil, processing_units: nil, labels: nil) ⇒ Instance::Job
Creates a Cloud Spanner instance and starts preparing it to begin serving.
-
#database(instance_id, database_id) ⇒ Google::Cloud::Spanner::Database?
Retrieves a database by unique identifier.
-
#databases(instance_id, token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Database>
Retrieves the list of databases for the project.
-
#instance(instance_id) ⇒ Google::Cloud::Spanner::Instance?
Retrieves a Cloud Spanner instance by unique identifier.
-
#instance_config(instance_config_id) ⇒ Google::Cloud::Spanner::Instance::Config?
Retrieves an instance configuration by unique identifier.
-
#instance_configs(token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Instance::Config>
Retrieves the list of instance configurations for the project.
-
#instances(token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Instance>
Retrieves the list of Cloud Spanner instances for the project.
-
#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) ⇒ Client
Creates a Cloud Spanner batch client. A batch client is used to read data across multiple machines or processes.
615 616 617 618 619 620 621 |
# File 'lib/google/cloud/spanner/project.rb', line 615 def batch_client instance_id, database_id, labels: nil, query_options: nil # Convert from possible Google::Protobuf::Map labels = Hash[labels.map { |k, v| [String(k), String(v)] }] if labels BatchClient.new self, instance_id, database_id, session_labels: labels, query_options: end |
#client(instance_id, database_id, pool: {}, labels: nil, query_options: nil) ⇒ Client
Creates a Cloud Spanner client. A client is used to read and/or modify data in a Cloud Spanner database.
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
# File 'lib/google/cloud/spanner/project.rb', line 539 def client instance_id, database_id, pool: {}, labels: nil, query_options: nil # Convert from possible Google::Protobuf::Map labels = Hash[labels.map { |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: end |
#create_database(instance_id, database_id, statements: [], encryption_config: nil) ⇒ Database::Job
Creates a database and starts preparing it to begin serving.
See Database::Job.
459 460 461 462 463 464 465 |
# File 'lib/google/cloud/spanner/project.rb', line 459 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
Creates a Cloud Spanner instance and starts preparing it to begin serving.
See Instance::Job.
245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/google/cloud/spanner/project.rb', line 245 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 = Hash[labels.map { |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?
Retrieves a database by unique identifier.
385 386 387 388 389 390 391 |
# File 'lib/google/cloud/spanner/project.rb', line 385 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>
Retrieves the list of databases for the project.
358 359 360 361 362 |
# File 'lib/google/cloud/spanner/project.rb', line 358 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?
Retrieves a Cloud Spanner instance by unique identifier.
155 156 157 158 159 160 161 |
# File 'lib/google/cloud/spanner/project.rb', line 155 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?
Retrieves an instance configuration by unique identifier.
318 319 320 321 322 323 324 |
# File 'lib/google/cloud/spanner/project.rb', line 318 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>
Retrieves the list of instance configurations for the project.
289 290 291 292 293 |
# File 'lib/google/cloud/spanner/project.rb', line 289 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>
Retrieves the list of Cloud Spanner instances for the project.
129 130 131 132 133 |
# File 'lib/google/cloud/spanner/project.rb', line 129 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 |