2929
3030__all__ = ("SpannerConnectionParams" , "SpannerDriverFeatures" , "SpannerPoolParams" , "SpannerSyncConfig" )
3131
32+ _DEFAULT_SESSION_TRANSACTION : bool = True
33+ """Default ``transaction`` flag for ``provide_session`` / ``provide_connection``.
34+
35+ ``True`` yields a write-capable :class:`Transaction` context matching every
36+ other sqlspec adapter. Read-only :class:`Snapshot` contexts are available via
37+ :meth:`SpannerSyncConfig.provide_read_session`. Pulled into a module-level
38+ constant so an eventual ``SpannerAsyncConfig`` can import the same default."""
39+
3240
3341class SpannerConnectionParams (TypedDict ):
3442 """Spanner connection parameters."""
@@ -278,27 +286,38 @@ def _close_pool(self) -> None:
278286 self ._client = None
279287 self ._database = None
280288
281- def provide_connection (self , * args : Any , transaction : "bool" = False , ** kwargs : Any ) -> "SpannerConnectionContext" :
282- """Yield a Snapshot (default) or Transaction context from the configured pool.
289+ def provide_connection (
290+ self , * args : Any , transaction : "bool" = _DEFAULT_SESSION_TRANSACTION , ** kwargs : Any
291+ ) -> "SpannerConnectionContext" :
292+ """Yield a Transaction (default) or Snapshot context from the configured pool.
283293
284294 Args:
285295 *args: Additional positional arguments (unused, for interface compatibility).
286- transaction: If True, yields a Transaction context that supports
287- execute_update() for DML statements. If False (default) , yields
296+ transaction: If True (default) , yields a Transaction context that
297+ supports execute_update() for DML statements. If False, yields
288298 a read-only Snapshot context for SELECT queries.
289299 **kwargs: Additional keyword arguments (unused, for interface compatibility).
290300 """
291301 return SpannerConnectionContext (self , transaction = transaction )
292302
293303 def provide_session (
294- self , * args : Any , statement_config : "StatementConfig | None" = None , transaction : "bool" = False , ** kwargs : Any
304+ self ,
305+ * args : Any ,
306+ statement_config : "StatementConfig | None" = None ,
307+ transaction : "bool" = _DEFAULT_SESSION_TRANSACTION ,
308+ ** kwargs : Any ,
295309 ) -> "SpannerSessionContext" :
296310 """Provide a Spanner driver session context manager.
297311
312+ Returns a write-capable Transaction session by default, matching every
313+ other sqlspec adapter. Pass ``transaction=False`` or use
314+ :meth:`provide_read_session` to obtain a read-only Snapshot session.
315+
298316 Args:
299317 *args: Additional arguments.
300318 statement_config: Optional statement configuration override.
301- transaction: Whether to use a transaction.
319+ transaction: Whether to use a Transaction (True, default) or
320+ Snapshot (False).
302321 **kwargs: Additional keyword arguments.
303322
304323 Returns:
@@ -318,17 +337,18 @@ def provide_session(
318337 def provide_write_session (
319338 self , * args : Any , statement_config : "StatementConfig | None" = None , ** kwargs : Any
320339 ) -> "SpannerSessionContext" :
321- """Provide a Spanner driver write session context manager.
340+ """Provide a write-capable Spanner session (alias for :meth:`provide_session`)."""
341+ return self .provide_session (* args , statement_config = statement_config , transaction = True , ** kwargs )
322342
323- Args:
324- *args: Additional arguments.
325- statement_config: Optional statement configuration override.
326- **kwargs: Additional keyword arguments .
343+ def provide_read_session (
344+ self , * args : Any , statement_config : "StatementConfig | None" = None , ** kwargs : Any
345+ ) -> "SpannerSessionContext" :
346+ """Provide a read-only Snapshot Spanner session .
327347
328- Returns:
329- A Spanner driver write session context manager .
348+ Use for query workloads that benefit from Spanner's snapshot reads.
349+ For DDL/DML, use :meth:`provide_session` ( write-capable by default) .
330350 """
331- return self .provide_session (* args , statement_config = statement_config , transaction = True , ** kwargs )
351+ return self .provide_session (* args , statement_config = statement_config , transaction = False , ** kwargs )
332352
333353 def get_signature_namespace (self ) -> "dict[str, Any]" :
334354 """Get the signature namespace for SpannerSyncConfig types.
0 commit comments