32
32
33
33
def init_tcp_connection_engine ():
34
34
# [START cloud_sql_server_sqlalchemy_create_tcp]
35
+ # [START cloud_sql_sqlserver_sqlalchemy_create_tcp]
35
36
# Remember - storing secrets in plaintext is potentially unsafe. Consider using
36
37
# something like https://cloud.google.com/secret-manager/docs/overview to help keep
37
38
# secrets secret.
@@ -61,32 +62,41 @@ def init_tcp_connection_engine():
61
62
# ... Specify additional properties here.
62
63
# [START_EXCLUDE]
63
64
# [START cloud_sql_server_sqlalchemy_limit]
65
+ # [START cloud_sql_sqlserver_sqlalchemy_limit]
64
66
# Pool size is the maximum number of permanent connections to keep.
65
67
pool_size = 5 ,
66
68
# Temporarily exceeds the set pool_size if no connections are available.
67
69
max_overflow = 2 ,
68
70
# The total number of concurrent connections for your application will be
69
71
# a total of pool_size and max_overflow.
72
+ # [END cloud_sql_sqlserver_sqlalchemy_limit]
70
73
# [END cloud_sql_server_sqlalchemy_limit]
71
74
# [START cloud_sql_server_sqlalchemy_backoff]
75
+ # [START cloud_sql_sqlserver_sqlalchemy_backoff]
72
76
# SQLAlchemy automatically uses delays between failed connection attempts,
73
77
# but provides no arguments for configuration.
78
+ # [END cloud_sql_sqlserver_sqlalchemy_backoff]
74
79
# [END cloud_sql_server_sqlalchemy_backoff]
75
80
# [START cloud_sql_server_sqlalchemy_timeout]
81
+ # [START cloud_sql_sqlserver_sqlalchemy_timeout]
76
82
# 'pool_timeout' is the maximum number of seconds to wait when retrieving a
77
83
# new connection from the pool. After the specified amount of time, an
78
84
# exception will be thrown.
79
85
pool_timeout = 30 , # 30 seconds
86
+ # [END cloud_sql_sqlserver_sqlalchemy_timeout]
80
87
# [END cloud_sql_server_sqlalchemy_timeout]
81
88
# [START cloud_sql_server_sqlalchemy_lifetime]
89
+ # [START cloud_sql_sqlserver_sqlalchemy_lifetime]
82
90
# 'pool_recycle' is the maximum number of seconds a connection can persist.
83
91
# Connections that live longer than the specified amount of time will be
84
92
# reestablished
85
93
pool_recycle = 1800 , # 30 minutes
94
+ # [END cloud_sql_sqlserver_sqlalchemy_lifetime]
86
95
# [END cloud_sql_server_sqlalchemy_lifetime]
87
96
echo = True # debug
88
97
# [END_EXCLUDE]
89
98
)
99
+ # [END cloud_sql_sqlserver_sqlalchemy_create_tcp]
90
100
# [END cloud_sql_server_sqlalchemy_create_tcp]
91
101
92
102
return pool
@@ -148,6 +158,7 @@ def save_vote():
148
158
return Response (response = "Invalid team specified." , status = 400 )
149
159
150
160
# [START cloud_sql_server_sqlalchemy_connection]
161
+ # [START cloud_sql_sqlserver_sqlalchemy_connection]
151
162
# Preparing a statement before hand can help protect against injections.
152
163
stmt = sqlalchemy .text (
153
164
"INSERT INTO votes (time_cast, candidate)"
@@ -169,6 +180,7 @@ def save_vote():
169
180
"application logs for more details." ,
170
181
)
171
182
# [END_EXCLUDE]
183
+ # [END cloud_sql_sqlserver_sqlalchemy_connection]
172
184
# [END cloud_sql_server_sqlalchemy_connection]
173
185
174
186
return Response (
0 commit comments