def snapshot_checkout(self): """Get a Cloud Spanner snapshot. Initiate a new multi-use snapshot, if there is no snapshot in this connection yet. Return the existing one otherwise. :rtype: :class:`google.cloud.spanner_v1.snapshot.Snapshot` :returns: A Cloud Spanner snapshot object, ready to use. """ if self.read_only and not self.autocommit: if not self._snapshot: self._snapshot = Snapshot(self._session_checkout(), multi_use=True, **self.staleness) self._snapshot.begin() return self._snapshot
def snapshot(self, **kw): """Create a snapshot to perform a set of reads with shared staleness. See https://cloud.google.com/spanner/reference/rpc/google.spanner.v1#google.spanner.v1.TransactionOptions.ReadOnly :type kw: dict :param kw: Passed through to :class:`~google.cloud.spanner_v1.snapshot.Snapshot` ctor. :rtype: :class:`~google.cloud.spanner_v1.snapshot.Snapshot` :returns: a snapshot bound to this session :raises ValueError: if the session has not yet been created. """ if self._session_id is None: raise ValueError("Session has not been created.") return Snapshot(self, **kw)
def __enter__(self): """Begin ``with`` block.""" session = self._session = self._database._pool.get() return Snapshot(session, **self._kw)