You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+20
Original file line number
Diff line number
Diff line change
@@ -114,6 +114,7 @@ The `Connector` itself creates connection objects by calling its `connect` metho
114
114
In the Connector's `connect` method below, input your connection string as the first positional argument and the name of the database driver for the second positional argument. Insert the rest of your connection keyword arguments like user, password and database. You can also set the optional `timeout` or `ip_type` keyword arguments.
115
115
116
116
To use this connector with SQLAlchemy, use the `creator` argument for `sqlalchemy.create_engine`:
117
+
117
118
```python
118
119
from google.cloud.sql.connector import Connector
119
120
import sqlalchemy
@@ -140,6 +141,7 @@ pool = sqlalchemy.create_engine(
140
141
```
141
142
142
143
The returned connection pool engine can then be used to query and modify the database.
144
+
143
145
```python
144
146
# insert statement
145
147
insert_stmt = sqlalchemy.text(
@@ -153,6 +155,9 @@ with pool.connect() as db_conn:
153
155
# query database
154
156
result = db_conn.execute(sqlalchemy.text("SELECT * from my_table")).fetchall()
155
157
158
+
# commit transaction (SQLAlchemy v2.X.X is commit as you go)
159
+
db_conn.commit()
160
+
156
161
# Do something with the results
157
162
for row in result:
158
163
print(row)
@@ -226,6 +231,9 @@ with pool.connect() as db_conn:
# commit transaction (SQLAlchemy v2.X.X is commit as you go)
235
+
db_conn.commit()
236
+
229
237
# query database
230
238
result = db_conn.execute(sqlalchemy.text("SELECT * from my_table")).fetchall()
231
239
@@ -235,8 +243,10 @@ with pool.connect() as db_conn:
235
243
```
236
244
237
245
### Specifying Public or Private IP
246
+
238
247
The Cloud SQL Connector for Python can be used to connect to Cloud SQL instances using both public and private IP addresses. To specify which IP address to use to connect, set the `ip_type` keyword argument Possible values are `IPTypes.PUBLIC` and `IPTypes.PRIVATE`.
239
248
Example:
249
+
240
250
```python
241
251
from google.cloud.sql.connector import IPTypes
242
252
@@ -251,6 +261,7 @@ connector.connect(
251
261
Note: If specifying Private IP, your application must already be in the same VPC network as your Cloud SQL Instance.
252
262
253
263
### IAM Authentication
264
+
254
265
Connections using [Automatic IAM database authentication](https://cloud.google.com/sql/docs/postgres/authentication#automatic) are supported when using Postgres or MySQL drivers.
255
266
First, make sure to [configure your Cloud SQL Instance to allow IAM authentication](https://cloud.google.com/sql/docs/postgres/create-edit-iam-instances#configure-iam-db-instance)
256
267
and [add an IAM database user](https://cloud.google.com/sql/docs/postgres/create-manage-iam-users#creating-a-database-user).
@@ -262,6 +273,7 @@ In the call to connect, set the `enable_iam_auth` keyword argument to true and t
262
273
> MySQL: For an IAM user account, this is the user's email address, without the @ or domain name. For example, for `[email protected]`, set the `user` argument to `test-user`. For a service account, this is the service account's email address without the `@project-id.iam.gserviceaccount.com` suffix.
263
274
264
275
Example:
276
+
265
277
```python
266
278
connector.connect(
267
279
"project:region:instance",
@@ -273,9 +285,11 @@ connector.connect(
273
285
```
274
286
275
287
### SQL Server Active Directory Authentication
288
+
276
289
Active Directory authentication for SQL Server instances is currently only supported on Windows. First, make sure to follow [these steps](https://cloud.google.com/blog/topics/developers-practitioners/creating-sql-server-instance-integrated-active-directory-using-google-cloud-sql) to set up a Managed AD domain and join your Cloud SQL instance to the domain. [See here for more info on Cloud SQL Active Directory integration](https://cloud.google.com/sql/docs/sqlserver/ad).
277
290
278
291
Once you have followed the steps linked above, you can run the following code to return a connection object:
0 commit comments