File tree Expand file tree Collapse file tree 4 files changed +68
-0
lines changed
appengine/standard_python37/spanner Expand file tree Collapse file tree 4 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ runtime : python37
2
+
3
+ env_variables :
4
+ SPANNER_INSTANCE : " YOUR-SPANNER-INSTANCE-ID"
5
+ SPANNER_DATABASE : " YOUR-SPANNER-DATABASE-ID"
Original file line number Diff line number Diff line change
1
+ # Copyright 2018 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # [START gae_python37_cloudsql_mysql]
16
+ import os
17
+
18
+ from flask import Flask
19
+ from google .cloud import spanner
20
+
21
+ app = Flask (__name__ )
22
+ spanner_client = spanner .Client ()
23
+
24
+ instance_id = os .environ .get ('SPANNER_INSTANCE' )
25
+ database_id = os .environ .get ('SPANNER_DATABASE' )
26
+
27
+
28
+ @app .route ('/' )
29
+ def main ():
30
+ database = spanner_client .instance (instance_id ).database (database_id )
31
+ with database .snapshot () as snapshot :
32
+ cursor = snapshot .execute_sql ('SELECT 1' )
33
+ results = list (cursor )
34
+
35
+ return 'Query Result: {}' .format (results [0 ][0 ])
Original file line number Diff line number Diff line change
1
+ # Copyright 2018 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ def test_main ():
17
+ import main
18
+
19
+ main .database_id = 'example-db'
20
+
21
+ main .app .testing = True
22
+ client = main .app .test_client ()
23
+
24
+ r = client .get ('/' )
25
+ assert r .status_code == 200
26
+ assert 'Query Result: 1' in r .data .decode ('utf-8' )
Original file line number Diff line number Diff line change
1
+ google-cloud-spanner == 1.6.0
2
+ Flask == 1.0.2
You can’t perform that action at this time.
0 commit comments