@@ -103,6 +103,11 @@ class DatabaseWrapper(BaseDatabaseWrapper):
103
103
104
104
@property
105
105
def instance (self ):
106
+ """Reference to a Cloud Spanner Instance containing the Database.
107
+
108
+ :rtype: :class:`~google.cloud.spanner_v1.instance.Instance`
109
+ :returns: A new instance owned by the existing Spanner Client.
110
+ """
106
111
return spanner .Client ().instance (self .settings_dict ["INSTANCE" ])
107
112
108
113
@property
@@ -112,6 +117,12 @@ def _nodb_connection(self):
112
117
)
113
118
114
119
def get_connection_params (self ):
120
+ """Retrieve the connection parameters.
121
+
122
+ :rtype: dict
123
+ :returns: A dictionary containing the Spanner connection parameters
124
+ in Django Spanner format.
125
+ """
115
126
return {
116
127
"project" : self .settings_dict ["PROJECT" ],
117
128
"instance_id" : self .settings_dict ["INSTANCE" ],
@@ -120,20 +131,52 @@ def get_connection_params(self):
120
131
** self .settings_dict ["OPTIONS" ],
121
132
}
122
133
123
- def get_new_connection (self , conn_params ):
134
+ def get_new_connection (self , ** conn_params ):
135
+ """Create a new connection with corresponding connection parameters.
136
+
137
+ :type conn_params: list
138
+ :param conn_params: A List of the connection parameters for
139
+ :class:`~google.cloud.spanner_dbapi.connection.Connection`
140
+
141
+ :rtype: :class:`google.cloud.spanner_dbapi.connection.Connection`
142
+ :returns: A new Spanner DB API Connection object associated with the
143
+ given Google Cloud Spanner resource.
144
+
145
+ :raises: :class:`ValueError` in case the given instance/database
146
+ doesn't exist.
147
+ """
124
148
return Database .connect (** conn_params )
125
149
126
150
def init_connection_state (self ):
151
+ """Initialize the state of the existing connection."""
127
152
pass
128
153
129
154
def create_cursor (self , name = None ):
155
+ """Create a new Database cursor.
156
+
157
+ :type name: str
158
+ :param name: Currently not used.
159
+
160
+ :rtype: :class:`~google.cloud.spanner_dbapi.cursor.Cursor`
161
+ :returns: The Cursor for this connection.
162
+ """
130
163
return self .connection .cursor ()
131
164
132
165
def _set_autocommit (self , autocommit ):
166
+ """Set the Spanner transaction autocommit flag.
167
+
168
+ :type autocommit: bool
169
+ :param autocommit: The new value of the autocommit flag.
170
+ """
133
171
with self .wrap_database_errors :
134
172
self .connection .autocommit = autocommit
135
173
136
174
def is_usable (self ):
175
+ """Check whether the connection is valid.
176
+
177
+ :rtype: bool
178
+ :returns: True if the connection is open, otherwise False.
179
+ """
137
180
if self .connection is None :
138
181
return False
139
182
try :
0 commit comments