OVERVIEW.md in google-cloud-spanner-2.10.1 vs OVERVIEW.md in google-cloud-spanner-2.11.0
- old
+ new
@@ -21,96 +21,107 @@
allocation of resources that are used by Cloud Spanner databases. When you
create an instance, you choose where your data is stored and how many nodes are
used for your data. (For more information, see [Configuration
Guide](https://googleapis.dev/ruby/stackdriver/latest/file.INSTRUMENTATION_CONFIGURATION.html).
-Use {Google::Cloud::Spanner::Project#create_instance Project#create_instance} to
-create an instance:
+Use {Google::Cloud::Spanner::Admin::Instance#instance_admin
+Client#create_instance} to create an instance:
```ruby
require "google/cloud/spanner"
-spanner = Google::Cloud::Spanner.new
+instance_admin_client = \
+ Google::Cloud::Spanner::Admin::Instance.instance_admin project_id: "my-project"
-job = spanner.create_instance "my-instance",
- name: "My Instance",
- config: "regional-us-central1",
- nodes: 5,
- labels: { production: :env }
+project_path = \
+ instance_admin_client.project_path project: "my-project"
+config_path = \
+ instance_admin_client.instance_config_path project: "my-project",
+ instance_config: "regional-us-central1"
+instance_path = \
+ instance_admin_client.instance_path project: "my-project",
+ instance: "my-instance"
-job.done? #=> false
-job.reload! # API call
-job.done? #=> true
+job = instance_admin_client.create_instance parent: project_path,
+ instance_id: "my-instance",
+ instance: Google::Cloud::Spanner::Admin::Instance::V1::Instance.new({
+ name: instance_path
+ display_name: "My Instance",
+ config: config_path,
+ node_count: 5,
+ labels: { "production": :env }
+ })
-if job.error?
- status = job.error
-else
- instance = job.instance
-end
+job.wait_until_done!
+instance = job.results
```
## Creating databases
Now that you have created an instance, you can create a database. Cloud
Spanner databases hold the tables and indexes that allow you to read and
write data. You may create multiple databases in an instance.
-Use {Google::Cloud::Spanner::Project#create_database Project#create_database}
-(or {Google::Cloud::Spanner::Instance#create_database Instance#create_database})
-to create a database:
+Use {Google::Cloud::Spanner::Admin::Database#database_admin
+Client#create_database} to create a database:
```ruby
require "google/cloud/spanner"
-spanner = Google::Cloud::Spanner.new
+db_admin_client = \
+ Google::Cloud::Spanner::Admin::Database.database_admin project_id: "my-project"
-job = spanner.create_database "my-instance", "my-database"
+instance_path = \
+ db_admin_client.instance_path project: "my-project", instance: "my-instance"
-job.done? #=> false
-job.reload! # API call
-job.done? #=> true
+job = db_admin_client.create_database parent: instance_path,
+ create_statement: "CREATE DATABASE my-database",
-if job.error?
- status = job.error
-else
- database = job.database
-end
+job.wait_until_done!
+database = job.results
```
## Updating database schemas
Cloud Spanner supports schema updates to a database while the database
continues to serve traffic. Schema updates do not require taking the
database offline and they do not lock entire tables or columns; you can
continue writing data to the database during the schema update.
-Use {Google::Cloud::Spanner::Database#update Database#update} to execute one or
-more statements in Cloud Spanner's Data Definition Language (DDL):
+Use {Google::Cloud::Spanner::Admin::Database#database_admin
+Client#update_database_ddl} to execute one or more statements in Cloud Spanner's
+Data Definition Language (DDL):
```ruby
require "google/cloud/spanner"
-spanner = Google::Cloud::Spanner.new
+db_admin_client = \
+ Google::Cloud::Spanner::Admin::Database.database_admin project_id: "my-project"
-database = spanner.database "my-instance", "my-database"
-
+db_path = db_admin_client.database_path project: "my-project",
+ instance: "my-instance",
+ database: "my-database"
add_users_table_sql = %q(
CREATE TABLE users (
id INT64 NOT NULL,
username STRING(25) NOT NULL,
name STRING(45) NOT NULL,
email STRING(128),
) PRIMARY KEY(id)
)
-database.update statements: [add_users_table_sql]
+job = db_admin_client.update_database_ddl database: db_path,
+ statements: [add_users_table_sql]
+
+job.wait_until_done!
+database = job.results
```
## Creating clients
-In order to read and/or write data, you must create a database client. You can
-think of a client as a database connection: All of your interactions with Cloud
+In order to read and/or write data, you must create a data client. You can think
+of a client as a database connection: All of your interactions with Cloud
Spanner data must go through a client. Typically you create a client when your
application starts up, then you re-use that client to read, write, and execute
transactions.
Use {Google::Cloud::Spanner::Project#client Project#client} to create a client:
@@ -287,36 +298,44 @@
end
```
## Deleting databases
-Use {Google::Cloud::Spanner::Database#drop Database#drop} to delete a database:
+Use {Google::Cloud::Spanner::Admin::Database#database_admin
+Client#drop_database} to delete a database:
```ruby
require "google/cloud/spanner"
-spanner = Google::Cloud::Spanner.new
+db_admin_client = \
+ Google::Cloud::Spanner::Admin::Database.database_admin project_id: "my-project"
-database = spanner.database "my-instance", "my-database"
-
-database.drop
+db_path = db_admin_client.database_path project: "my-project",
+ instance: "my-instance",
+ database: "my-database"
+db_admin_client.drop_database database: db_path
```
## Deleting instances
When you delete an instance, all databases within it are automatically deleted.
(If you only delete databases and not your instance, you will still incur
-charges for the instance.) Use {Google::Cloud::Spanner::Instance#delete
-Instance#delete} to delete an instance:
+charges for the instance.)
+Use {Google::Cloud::Spanner::Admin::Instance#instance_admin
+Client#delete_instance} to delete an instance:
+
```ruby
require "google/cloud/spanner"
-spanner = Google::Cloud::Spanner.new
+instance_admin_client = \
+ Google::Cloud::Spanner::Admin::Instance.instance_admin project_id: "my-project"
-instance = spanner.instance "my-instance"
+instance_path = \
+ instance_admin_client.instance_path project: "my-project",
+ instance: "my-instance"
-instance.delete
+instance_admin_client.delete_instance name: instance_path
```
## Additional information
Cloud Spanner can be configured to use gRPC's logging. To learn more, see the