1
1
Database Admin
2
2
==============
3
3
4
- After creating a :class: `~google.cloud.spanner .instance.Instance `, you can
4
+ After creating an :class: `~google.cloud.spanner_v1 .instance.Instance `, you can
5
5
interact with individual databases for that instance.
6
6
7
7
8
8
List Databases
9
9
--------------
10
10
11
11
To iterate over all existing databases for an instance, use its
12
- :meth: `~google.cloud.spanner .instance.Instance.list_databases ` method:
12
+ :meth: `~google.cloud.spanner_v1 .instance.Instance.list_databases ` method:
13
13
14
14
.. code :: python
15
15
16
16
for database in instance.list_databases():
17
17
# `database` is a `Database` object.
18
18
19
- This method yields :class: `~.spanner_admin_database_v1.types .Database `
19
+ This method yields :class: `~google.cloud.spanner_v1.database .Database `
20
20
objects.
21
21
22
22
23
23
Database Factory
24
24
----------------
25
25
26
- To create a :class: `~google.cloud.spanner .database.Database ` object:
26
+ To create a :class: `~google.cloud.spanner_v1 .database.Database ` object:
27
27
28
28
.. code :: python
29
29
30
30
database = instance.database(database_id, ddl_statements)
31
31
32
- - ``ddl_statements `` is a list of strings containing DDL for the new database.
32
+ - ``ddl_statements `` is a list of strings containing DDL statements for the new database.
33
33
34
- You can also use :meth: `Instance.database ` to create a local wrapper for
35
- a database that has already been created:
34
+ You can also use the :meth: `~google.cloud.spanner_v1.instance.Instance.database ` method
35
+ on an :class: `~google.cloud.spanner_v1.instance.Instance ` object to create a local wrapper
36
+ for a database that has already been created:
36
37
37
38
.. code :: python
38
39
@@ -43,7 +44,7 @@ Create a new Database
43
44
---------------------
44
45
45
46
After creating the database object, use its
46
- :meth: `~google.cloud.spanner .database.Database.create ` method to
47
+ :meth: `~google.cloud.spanner_v1 .database.Database.create ` method to
47
48
trigger its creation on the server:
48
49
49
50
.. code :: python
@@ -52,8 +53,8 @@ trigger its creation on the server:
52
53
53
54
.. note ::
54
55
55
- Creating an instance triggers a "long-running operation" and
56
- returns an :class: `~concurrent.futures.Future `-like object. Use
56
+ Creating a database triggers a "long-running operation" and
57
+ returns a :class: `~concurrent.futures.Future `-like object. Use
57
58
the :meth: `~concurrent.futures.Future.result ` method to wait for
58
59
and inspect the result.
59
60
@@ -62,21 +63,21 @@ Update an existing Database
62
63
---------------------------
63
64
64
65
After creating the database object, you can apply additional DDL statements
65
- via its :meth: `~google.cloud.spanner .database.Database.update_ddl ` method:
66
+ via its :meth: `~google.cloud.spanner_v1 .database.Database.update_ddl ` method:
66
67
67
68
.. code :: python
68
69
69
70
operation = database.update_ddl(ddl_statements, operation_id)
70
71
71
- - ``ddl_statements `` is a list of strings containing DDL to be applied to
72
- the database.
72
+ - ``ddl_statements `` is a list of strings containing DDL statements to be
73
+ applied to the database.
73
74
74
75
- ``operation_id `` is a string ID for the long-running operation.
75
76
76
77
.. note ::
77
78
78
- Update an instance triggers a "long-running operation" and
79
- returns a :class: `google.cloud.spanner .database.Operation `
79
+ Updating a database triggers a "long-running operation" and
80
+ returns an :class: `~ google.cloud.spanner_v1 .database.Operation `
80
81
object. See :ref: `check-on-current-database-operation ` for polling
81
82
to find out if the operation is completed.
82
83
@@ -85,7 +86,7 @@ Drop a Database
85
86
---------------
86
87
87
88
Drop a database using its
88
- :meth: `~google.cloud.spanner .database.Database.drop ` method:
89
+ :meth: `~google.cloud.spanner_v1 .database.Database.drop ` method:
89
90
90
91
.. code :: python
91
92
@@ -97,14 +98,15 @@ Drop a database using its
97
98
Check on Current Database Operation
98
99
-----------------------------------
99
100
100
- The :meth: `~google.cloud.spanner.database.Database.create ` and
101
- :meth: `~google.cloud.spanner.database.Database.update ` methods of instance
102
- object trigger long-running operations on the server, and return instances
101
+ The :meth: `~google.cloud.spanner_v1.database.Database.create ` and
102
+ :meth: `~google.cloud.spanner_v1.database.Database.update_ddl ` methods of the
103
+ :class: `~google.cloud.spanner_v1.database.Database ` object trigger
104
+ long-running operations on the server, and return operations
103
105
conforming to the :class: `~.concurrent.futures.Future ` class.
104
106
105
107
.. code :: python
106
108
107
- >> > operation = instance .create()
109
+ >> > operation = database .create()
108
110
>> > operation.result()
109
111
110
112
@@ -116,24 +118,25 @@ Use a Snapshot to Read / Query the Database
116
118
117
119
A snapshot represents a read-only point-in-time view of the database.
118
120
119
- Calling :meth: `~google.cloud.spanner .database.Database.snapshot ` with
121
+ Calling :meth: `~google.cloud.spanner_v1 .database.Database.snapshot ` with
120
122
no arguments creates a snapshot with strong concurrency:
121
123
122
124
.. code :: python
123
125
124
126
with database.snapshot() as snapshot:
125
127
do_something_with(snapshot)
126
128
127
- See :class: `~google.cloud.spanner .snapshot.Snapshot ` for the other options
129
+ See :class: `~google.cloud.spanner_v1 .snapshot.Snapshot ` for the other options
128
130
which can be passed.
129
131
130
132
.. note ::
131
133
132
- :meth: `~google.cloud.spanner .database.Database.snapshot ` returns an
134
+ :meth: `~google.cloud.spanner_v1 .database.Database.snapshot ` returns an
133
135
object intended to be used as a Python context manager (i.e., as the
134
- target of a ``with `` statement). Use the instance, and any result
135
- sets returned by its ``read `` or ``execute_sql `` methods, only inside
136
- the block created by the ``with `` statement.
136
+ target of a ``with `` statement). Perform all iterations within the
137
+ context of the ``with database.snapshot() `` block.
138
+
139
+
137
140
138
141
See :doc: `snapshot-usage ` for more complete examples of snapshot usage.
139
142
@@ -151,7 +154,7 @@ on the rows of tables in the database.
151
154
152
155
.. note ::
153
156
154
- :meth: `~google.cloud.spanner .database.Database.batch ` returns an
157
+ :meth: `~google.cloud.spanner_v1 .database.Database.batch ` returns an
155
158
object intended to be used as a Python context manager (i.e., as the
156
159
target of a ``with `` statement). It applies any changes made inside
157
160
the block of its ``with `` statement when exiting the block, unless an
@@ -187,26 +190,26 @@ transaction as a required argument:
187
190
188
191
.. note ::
189
192
190
- :meth: `~google.cloud.spanner .database.Database.run_in_transaction `
193
+ :meth: `~google.cloud.spanner_v1 .database.Database.run_in_transaction `
191
194
commits the transaction automatically if the "unit of work" function
192
195
returns without raising an exception.
193
196
194
197
.. note ::
195
198
196
- :meth: `~google.cloud.spanner .database.Database.run_in_transaction `
197
- retries the "unit of work" function if the read / query operatoins
198
- or the commit are aborted due to concurrent updates
199
+ :meth: `~google.cloud.spanner_v1 .database.Database.run_in_transaction `
200
+ retries the "unit of work" function if the read / query operations
201
+ or the commit are aborted due to concurrent updates.
199
202
200
203
See :doc: `transaction-usage ` for more complete examples of transaction usage.
201
204
202
205
Configuring a session pool for a database
203
206
-----------------------------------------
204
207
205
208
Under the covers, the ``snapshot ``, ``batch ``, and ``run_in_transaction ``
206
- methods use a pool of :class: `~google.cloud.spanner .session.Session ` objects
209
+ methods use a pool of :class: `~google.cloud.spanner_v1 .session.Session ` objects
207
210
to manage their communication with the back-end. You can configure
208
211
one of the pools manually to control the number of sessions, timeouts, etc.,
209
- and then passing it to the :class: `~google.cloud.spanner .database.Database `
212
+ and then pass it to the :class: `~google.cloud.spanner_v1 .database.Database `
210
213
constructor:
211
214
212
215
.. code-block :: python
@@ -221,12 +224,12 @@ constructor:
221
224
pool = spanner.FixedSizePool(size = 10 , default_timeout = 5 )
222
225
database = instance.database(DATABASE_NAME , pool = pool)
223
226
224
- Note that creating a database with a pool may presume that its database
225
- already exists, as it may need to pre-create sessions (rather than creating
226
- them on demand, as the default implementation does).
227
+ Note that creating a database with a pool will require the database to
228
+ already exist if the pool implementation needs to pre-create sessions
229
+ (rather than creating them on demand, as the default implementation does).
227
230
228
231
You can supply your own pool implementation, which must satisfy the
229
- contract laid out in :class: `~google.cloud.spanner .pool.AbstractSessionPool `:
232
+ contract laid out in :class: `~google.cloud.spanner_v1 .pool.AbstractSessionPool `:
230
233
231
234
.. code-block :: python
232
235
0 commit comments