Day #2: 20 Days of coding challenge
Today, I am preparing myself to make a backend server for an education mobile app. In which I will be using RESTful Apis to communicate with the server which will be then hosted on AWS/Heroku.
What do I have?
As of now I have an excel sheet which contains all the data which need to be available on the mobile app.
I converted the excel sheet into sqlite database. Now the challenge is that I will make rest api in python using flask and restplus and SQLAlchemy (ORM for database) to get data from SQL database which has an exixting schema (As the data came from an excel sheet). In order to map the existing schema with flask sqlalchemy I will use Reflect and Automap.
After stucking on errors and searching web I realised that I cannot auto map the table as it does not have a primary key. The last option was to access data using db session in flask sqlalchemy. Using below code. OR to make a new schema with existing data which can be a time taking task.
` table_name = db.Table(‘Learn’, db.metadata, autoload=True, autoload_with=db.engine) `
now I can access table content using normal sqlalchemy code
` authors = db.session.query(table_name).all()`
Wrap UP
From tomorrow I will create some endpoints for my rest apis.