Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit edaf68a

Browse filesBrowse files
authored
Update Cloud SQL connectivity sample region tags. (GoogleCloudPlatform#1993)
* Updated mysql/sqlalchemy region tags. * Updated postgres region tags. * Fix connect to connection.
1 parent e9bc7de commit edaf68a
Copy full SHA for edaf68a

File tree

Expand file treeCollapse file tree

2 files changed

+28
-28
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-28
lines changed

‎cloud-sql/mysql/sqlalchemy/main.py

Copy file name to clipboardExpand all lines: cloud-sql/mysql/sqlalchemy/main.py
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
db_user = os.environ.get("DB_USER")
2626
db_pass = os.environ.get("DB_PASS")
2727
db_name = os.environ.get("DB_NAME")
28-
cloud_sql_instance_name = os.environ.get("CLOUD_SQL_INSTANCE_NAME")
28+
cloud_sql_connection_name = os.environ.get("CLOUD_SQL_CONNECTION_NAME")
2929

3030
app = Flask(__name__)
3131

3232
logger = logging.getLogger()
3333

34-
# [START cloud_sql_mysql_connection_pool]
34+
# [START cloud_sql_mysql_sqlalchemy_create]
3535
# The SQLAlchemy engine will help manage interactions, including automatically
3636
# managing a pool of connections to your database
3737
db = sqlalchemy.create_engine(
@@ -43,43 +43,43 @@
4343
password=db_pass,
4444
database=db_name,
4545
query={
46-
'unix_socket': '/cloudsql/{}'.format(cloud_sql_instance_name)
46+
'unix_socket': '/cloudsql/{}'.format(cloud_sql_connection_name)
4747
}
4848
),
4949
# ... Specify additional properties here.
5050
# [START_EXCLUDE]
5151

52-
# [START cloud_sql_mysql_limit_connections]
52+
# [START cloud_sql_mysql_sqlalchemy_limit]
5353
# Pool size is the maximum number of permanent connections to keep.
5454
pool_size=5,
5555
# Temporarily exceeds the set pool_size if no connections are available.
5656
max_overflow=2,
5757
# The total number of concurrent connections for your application will be
5858
# a total of pool_size and max_overflow.
59-
# [END cloud_sql_mysql_limit_connections]
59+
# [END cloud_sql_mysql_sqlalchemy_limit]
6060

61-
# [START cloud_sql_mysql_connection_backoff]
61+
# [START cloud_sql_mysql_sqlalchemy_backoff]
6262
# SQLAlchemy automatically uses delays between failed connection attempts,
6363
# but provides no arguments for configuration.
64-
# [END cloud_sql_mysql_connection_backoff]
64+
# [END cloud_sql_mysql_sqlalchemy_backoff]
6565

66-
# [START cloud_sql_mysql_connection_timeout]
66+
# [START cloud_sql_mysql_sqlalchemy_timeout]
6767
# 'pool_timeout' is the maximum number of seconds to wait when retrieving a
6868
# new connection from the pool. After the specified amount of time, an
6969
# exception will be thrown.
7070
pool_timeout=30, # 30 seconds
71-
# [END cloud_sql_mysql_connection_timeout]
71+
# [END cloud_sql_mysql_sqlalchemy_timeout]
7272

73-
# [START cloud_sql_mysql_connection_lifetime]
73+
# [START cloud_sql_mysql_sqlalchemy_lifetime]
7474
# 'pool_recycle' is the maximum number of seconds a connection can persist.
7575
# Connections that live longer than the specified amount of time will be
7676
# reestablished
7777
pool_recycle=1800, # 30 minutes
78-
# [END cloud_sql_mysql_connection_lifetime]
78+
# [END cloud_sql_mysql_sqlalchemy_lifetime]
7979

8080
# [END_EXCLUDE]
8181
)
82-
# [END cloud_sql_mysql_connection_pool]
82+
# [END cloud_sql_mysql_sqlalchemy_create]
8383

8484

8585
@app.before_first_request
@@ -139,7 +139,7 @@ def save_vote():
139139
status=400
140140
)
141141

142-
# [START cloud_sql_mysql_example_statement]
142+
# [START cloud_sql_mysql_sqlalchemy_connection]
143143
# Preparing a statement before hand can help protect against injections.
144144
stmt = sqlalchemy.text(
145145
"INSERT INTO votes (time_cast, candidate)"
@@ -161,7 +161,7 @@ def save_vote():
161161
"application logs for more details."
162162
)
163163
# [END_EXCLUDE]
164-
# [END cloud_sql_mysql_example_statement]
164+
# [END cloud_sql_mysql_sqlalchemy_connection]
165165

166166
return Response(
167167
status=200,

‎cloud-sql/postgres/sqlalchemy/main.py

Copy file name to clipboardExpand all lines: cloud-sql/postgres/sqlalchemy/main.py
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
db_user = os.environ.get("DB_USER")
2626
db_pass = os.environ.get("DB_PASS")
2727
db_name = os.environ.get("DB_NAME")
28-
cloud_sql_instance_name = os.environ.get("CLOUD_SQL_INSTANCE_NAME")
28+
cloud_sql_connection_name = os.environ.get("CLOUD_SQL_CONNECTION_NAME")
2929

3030
app = Flask(__name__)
3131

3232
logger = logging.getLogger()
3333

34-
# [START cloud_sql_postgres_connection_pool]
34+
# [START cloud_sql_postgres_sqlalchemy_create]
3535
# The SQLAlchemy engine will help manage interactions, including automatically
3636
# managing a pool of connections to your database
3737
db = sqlalchemy.create_engine(
@@ -43,43 +43,43 @@
4343
password=db_pass,
4444
database=db_name,
4545
query={
46-
'unix_sock': '/cloudsql/{}'.format(cloud_sql_instance_name)
46+
'unix_sock': '/cloudsql/{}'.format(cloud_sql_connection_name)
4747
}
4848
),
4949
# ... Specify additional properties here.
5050
# [START_EXCLUDE]
5151

52-
# [START cloud_sql_postgres_limit_connections]
52+
# [START cloud_sql_postgres_sqlalchemy_limit]
5353
# Pool size is the maximum number of permanent connections to keep.
5454
pool_size=5,
5555
# Temporarily exceeds the set pool_size if no connections are available.
5656
max_overflow=2,
5757
# The total number of concurrent connections for your application will be
5858
# a total of pool_size and max_overflow.
59-
# [END cloud_sql_postgres_limit_connections]
59+
# [END cloud_sql_postgres_sqlalchemy_limit]
6060

61-
# [START cloud_sql_postgres_connection_backoff]
61+
# [START cloud_sql_postgres_sqlalchemy_backoff]
6262
# SQLAlchemy automatically uses delays between failed connection attempts,
6363
# but provides no arguments for configuration.
64-
# [END cloud_sql_postgres_connection_backoff]
64+
# [END cloud_sql_postgres_sqlalchemy_backoff]
6565

66-
# [START cloud_sql_postgres_connection_timeout]
66+
# [START cloud_sql_postgres_sqlalchemy_timeout]
6767
# 'pool_timeout' is the maximum number of seconds to wait when retrieving a
6868
# new connection from the pool. After the specified amount of time, an
6969
# exception will be thrown.
7070
pool_timeout=30, # 30 seconds
71-
# [END cloud_sql_postgres_connection_timeout]
71+
# [END cloud_sql_postgres_sqlalchemy_timeout]
7272

73-
# [START cloud_sql_postgres_connection_lifetime]
73+
# [START cloud_sql_postgres_sqlalchemy_lifetime]
7474
# 'pool_recycle' is the maximum number of seconds a connection can persist.
7575
# Connections that live longer than the specified amount of time will be
7676
# reestablished
7777
pool_recycle=1800, # 30 minutes
78-
# [END cloud_sql_postgres_connection_lifetime]
78+
# [END cloud_sql_postgres_sqlalchemy_lifetime]
7979

8080
# [END_EXCLUDE]
8181
)
82-
# [END cloud_sql_postgres_connection_pool]
82+
# [END cloud_sql_postgres_sqlalchemy_create]
8383

8484

8585
@app.before_first_request
@@ -139,7 +139,7 @@ def save_vote():
139139
status=400
140140
)
141141

142-
# [START cloud_sql_postgres_example_statement]
142+
# [START cloud_sql_postgres_sqlalchemy_connection]
143143
# Preparing a statement before hand can help protect against injections.
144144
stmt = sqlalchemy.text(
145145
"INSERT INTO votes (time_cast, candidate)"
@@ -161,7 +161,7 @@ def save_vote():
161161
"application logs for more details."
162162
)
163163
# [END_EXCLUDE]
164-
# [END cloud_sql_postgres_example_statement]
164+
# [END cloud_sql_postgres_sqlalchemy_connection]
165165

166166
return Response(
167167
status=200,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.