This repository contains Python backend files for a library website built using Flask, SQLite, REST API and Data Structures.
- Tools Used: DB Browser for SQLite, Postman, Visual Studio Code, Github Desktop
- Libraries used: flask, sqlite3, flask_sqlalchemy, sqlalchemy
- Data Structures Used: Linked List, Binary Search Tree, Stack, Queue, Hash Table
- DB Browser for SQLite: Allows the users to view the database via a graphical user interface. It is used to create, design, and edit database files compatible with SQLite.
- Postman: An API platform for building and using APIs.
- Flask: Micro web framework for creating APIs in Python. It is a middleware that is between the python application and the server.
- SQLite3: file-based SQL database used to integrate the SQLite database with Python.
- SQLAlchemy: Facilitates the communication between Python programs and databases.
- Flask-SQLAlchemy: Flask extension that makes using SQLAlchemy with Flask easier, providing you tools and methods to interact with your database in your Flask applications through SQLAlchemy.
- Object-Relational Mapping (ORM): Technique that lets you query and manipulate data from a database using an object-oriented paradigm.
- A virtual environment "venv" is created by the following command:
python3 -m venv venv
- The "venv" virtual environment is activated by the command (macOS):
. venv/bin/activate
- To install Flask:
pip install flask
- To install flask_sqlalchemy:
pip install flask_sqlalchemy
- To install sqlite3:
pip install pysqlite3
In the command line, to generate the database
- python
- from server import db,app
- app.app_context().push()
- db.create_all()
- exit()
- Author Table Values:
- Book Table values:
- POST - Add Author to Database
{ "fname":"Joanne", "lname":"Rowling", "country":"United Kingdom" }
- GET - Get Authors in Descending Order (Data Structure Used: Linked List)
- GET - Get Authors in Ascending Order (Data Structure Used: Linked List)
- GET - Get One Author by ID (Data Structure Used: Linked List)
User ID: 11
User ID: 22
- DELETE - Delete Author by ID
User ID: 10
User ID: 22
- GET - Get One Book by ID (Data Structure Used: Tree - Binary Search Tree Algorithm)
Book ID: 1
Book ID: 10
- GET - Get Book's Preface's ASCII value (Data Structure Used: Queue)
- POST - Add Book to Database
{ "title":"Harry Potter and the Deathly Hallows", "total_pages": 759, "rating": 4.62, "isbn": "9788893814560", "published_date": "2007-07-21", "preface": "Harry has been burdened with a dark, dangerous and seemingly impossible task: that of locating and destroying Voldemort's remaining Horcruxes. Never has Harry felt so alone, or faced a future so full of shadows. But Harry must somehow find within himself the strength to complete the task he has been given. He must leave the warmth, safety and companionship of The Burrow and follow without fear or hesitation the inexorable path laid out for him..." }
- DELETE - Delete last 5 Books (Data Structure Used: Stack)
Test Case 1: When 9 Books are present in the Database:
Test Case 2: When 4 Books are present in the Database
Test Case 3: When the Book Database is empty