Class: Google::Cloud::Spanner::Database
- Inherits:
-
Object
- Object
- Google::Cloud::Spanner::Database
- Defined in:
- lib/google/cloud/spanner/database.rb,
lib/google/cloud/spanner/database/job.rb,
lib/google/cloud/spanner/database/list.rb
Overview
Database
Represents a Cloud Spanner database. To use Cloud Spanner's read and write operations, you must first create a database. A database belongs to a Instance and contains tables and indexes. You may create multiple databases in an Instance.
See Instance#databases, Instance#database, and Instance#create_database.
To read and/or modify data in a Cloud Spanner database, use an instance of Client. See Project#client.
Defined Under Namespace
Instance Method Summary collapse
-
#creating? ⇒ Boolean
The database is still being created.
-
#database_id ⇒ String
The unique identifier for the database.
-
#ddl(force: nil) ⇒ Array<String>
Retrieve the Data Definition Language (DDL) statements that define database structures.
-
#drop ⇒ Boolean
Drops (deletes) the Cloud Spanner database.
-
#instance_id ⇒ String
The unique identifier for the instance.
-
#path ⇒ String
The full path for the database resource.
-
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this database.
-
#policy=(new_policy) ⇒ Policy
Updates the Cloud IAM access control policy for this database.
-
#project_id ⇒ String
The unique identifier for the project.
-
#ready? ⇒ Boolean
The database is fully created and ready for use.
-
#state ⇒ Symbol
The current database state.
-
#test_permissions(*permissions) ⇒ Array<Strings>
Tests the specified permissions against the Cloud IAM access control policy.
-
#update(statements: [], operation_id: nil) ⇒ Database::Job
Updates the database schema by adding Data Definition Language (DDL) statements to create, update, and delete tables and indexes.
Instance Method Details
#creating? ⇒ Boolean
The database is still being created. Operations on the database may
fail with FAILED_PRECONDITION
in this state.
109 110 111 |
# File 'lib/google/cloud/spanner/database.rb', line 109 def creating? state == :CREATING end |
#database_id ⇒ String
The unique identifier for the database.
80 81 82 83 |
# File 'lib/google/cloud/spanner/database.rb', line 80 def database_id Admin::Database::V1::DatabaseAdminClient .match_database_from_database_name @grpc.name end |
#ddl(force: nil) ⇒ Array<String>
Retrieve the Data Definition Language (DDL) statements that define database structures. DDL statements are used to create, update, and delete tables and indexes.
153 154 155 156 157 158 |
# File 'lib/google/cloud/spanner/database.rb', line 153 def ddl force: nil return @ddl if @ddl && !force ensure_service! ddl_grpc = service.get_database_ddl instance_id, database_id @ddl = ddl_grpc.statements end |
#drop ⇒ Boolean
Drops (deletes) the Cloud Spanner database.
220 221 222 223 224 |
# File 'lib/google/cloud/spanner/database.rb', line 220 def drop ensure_service! service.drop_database instance_id, database_id true end |
#instance_id ⇒ String
The unique identifier for the instance.
73 74 75 76 |
# File 'lib/google/cloud/spanner/database.rb', line 73 def instance_id Admin::Database::V1::DatabaseAdminClient .match_instance_from_database_name @grpc.name end |
#path ⇒ String
The full path for the database resource. Values are of the form
projects/<project_id>/instances/<instance_id>/databases/<database_id>
.
91 92 93 |
# File 'lib/google/cloud/spanner/database.rb', line 91 def path @grpc.name end |
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this database.
260 261 262 263 264 265 266 267 |
# File 'lib/google/cloud/spanner/database.rb', line 260 def policy ensure_service! grpc = service.get_database_policy instance_id, database_id policy = Policy.from_grpc grpc return policy unless block_given? yield policy self.policy = policy end |
#policy=(new_policy) ⇒ Policy
Updates the Cloud IAM access control
policy for this database. The policy should be read from #policy.
See Policy for an explanation of the policy
etag
property and how to modify policies.
You can also update the policy by passing a block to #policy, which will call this method internally after the block completes.
298 299 300 301 302 303 |
# File 'lib/google/cloud/spanner/database.rb', line 298 def policy= new_policy ensure_service! grpc = service.set_database_policy \ instance_id, database_id, new_policy.to_grpc Policy.from_grpc grpc end |
#project_id ⇒ String
The unique identifier for the project.
66 67 68 69 |
# File 'lib/google/cloud/spanner/database.rb', line 66 def project_id Admin::Database::V1::DatabaseAdminClient .match_project_from_database_name @grpc.name end |
#ready? ⇒ Boolean
The database is fully created and ready for use.
116 117 118 |
# File 'lib/google/cloud/spanner/database.rb', line 116 def ready? state == :READY end |
#state ⇒ Symbol
The current database state. Possible values are :CREATING
and
:READY
.
101 102 103 |
# File 'lib/google/cloud/spanner/database.rb', line 101 def state @grpc.state end |
#test_permissions(*permissions) ⇒ Array<Strings>
Tests the specified permissions against the Cloud IAM access control policy.
345 346 347 348 349 350 351 352 |
# File 'lib/google/cloud/spanner/database.rb', line 345 def * = Array().flatten = Array().flatten ensure_service! grpc = service. \ instance_id, database_id, grpc. end |
#update(statements: [], operation_id: nil) ⇒ Database::Job
Updates the database schema by adding Data Definition Language (DDL) statements to create, update, and delete tables and indexes.
199 200 201 202 203 204 205 |
# File 'lib/google/cloud/spanner/database.rb', line 199 def update statements: [], operation_id: nil ensure_service! grpc = service.update_database_ddl instance_id, database_id, statements: statements, operation_id: operation_id Database::Job.from_grpc grpc, service end |