2525db_user = os .environ .get ("DB_USER" )
2626db_pass = os .environ .get ("DB_PASS" )
2727db_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
3030app = Flask (__name__ )
3131
3232logger = 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
3737db = sqlalchemy .create_engine (
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