Demo on how to set up a Flask webservice that allows plain sql read access to database tables
Create a database and an application that accepts HTTP Get calls with the sql
parameter and returns the results of that query as json.
Make sure you have sqlite3, python and Flask installed.
sqlite3 nbastats.db < schema.sql
: this will execute the sql statements inschema.sql
that will create a tablenbastats
.python load_data.py
: this will load the data fromdata.csv
(contains some NBA sats) into the database.python app.py
: runs the app. It will be accessible at localhost:5000
Select only players from the Indiana pacers:
http://localhost:5000/?sql=select name,team from nbastats where team='Ind'
Aggregate the points made by team:
http://localhost:5000/?sql=select sum(points_made),team from nbastats group by team
The app does some very basic checking of the sql statement that is sent. It is absolutely not secure yet.