-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (32 loc) · 1.12 KB
/
app.py
File metadata and controls
40 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import Flask, jsonify
import cx_Oracle
# declare constants for flask app
HOST = '0.0.0.0'
PORT = 5000
# initialize flask application
app = Flask(__name__)
# automonous data warehouse connection constants
# update below with your db credentials
# add wallet files to wallet folder
DB = "<database_connection_name_in_tnsnames.ora>"
DB_USER = "<database_user>"
DB_PASSWORD = "<database_password>"
connection = cx_Oracle.connect(DB_USER, DB_PASSWORD, DB)
# api endpoint returning version of database from automonous data warehouse
@app.route('/api/version')
def version():
return jsonify(status='success', db_version=connection.version)
# sample api endpoint returning data from automonous data warehouse
# update sql based on your database tables
@app.route('/api/test')
def test():
data=[]
cursor = connection.cursor()
for row in cursor.execute("SELECT * FROM table WHERE ROWNUM <= 20"):
data.append(row)
cursor.close()
return jsonify(status='success', db_version=connection.version, data=data)
if __name__ == '__main__':
app.run(host=HOST,
debug=True,
port=PORT)