|
47 | 47 | from google.cloud.spanner_v1 import TransactionSelector |
48 | 48 | from google.cloud.spanner_v1 import TransactionOptions |
49 | 49 | from google.cloud.spanner_v1 import RequestOptions |
| 50 | +from google.cloud.spanner_v1 import SpannerAsyncClient |
50 | 51 | from google.cloud.spanner_v1 import SpannerClient |
51 | 52 | from google.cloud.spanner_v1._helpers import _merge_query_options |
52 | 53 | from google.cloud.spanner_v1._helpers import ( |
@@ -143,6 +144,7 @@ class Database(object): |
143 | 144 | """ |
144 | 145 |
|
145 | 146 | _spanner_api = None |
| 147 | + _spanner_async_api: SpannerAsyncClient = None |
146 | 148 |
|
147 | 149 | def __init__( |
148 | 150 | self, |
@@ -438,6 +440,28 @@ def spanner_api(self): |
438 | 440 | ) |
439 | 441 | return self._spanner_api |
440 | 442 |
|
| 443 | + @property |
| 444 | + def spanner_async_api(self): |
| 445 | + if self._spanner_async_api is None: |
| 446 | + client_info = self._instance._client._client_info |
| 447 | + client_options = self._instance._client._client_options |
| 448 | + if self._instance.emulator_host is not None: |
| 449 | + channel = grpc.aio.insecure_channel(target=self._instance.emulator_host) |
| 450 | + transport = SpannerGrpcTransport(channel=channel) |
| 451 | + self._spanner_async_api = SpannerAsyncClient( |
| 452 | + client_info=client_info, transport=transport |
| 453 | + ) |
| 454 | + return self._spanner_async_api |
| 455 | + credentials = self._instance._client.credentials |
| 456 | + if isinstance(credentials, google.auth.credentials.Scoped): |
| 457 | + credentials = credentials.with_scopes((SPANNER_DATA_SCOPE,)) |
| 458 | + self._spanner_async_api = SpannerAsyncClient( |
| 459 | + credentials=credentials, |
| 460 | + client_info=client_info, |
| 461 | + client_options=client_options, |
| 462 | + ) |
| 463 | + return self._spanner_async_api |
| 464 | + |
441 | 465 | def __eq__(self, other): |
442 | 466 | if not isinstance(other, self.__class__): |
443 | 467 | return NotImplemented |
|
0 commit comments