This project demonstrates how to interact with a SQL database using Python. It connects to a database, performs CRUD (Create, Read, Update, Delete) operations, and executes SQL queries. The script also integrates with a CI/CD pipeline for automated testing.
- Connects to a SQL database.
- Performs CRUD operations.
- Executes at least two SQL queries.
- Automated testing of database operations through a CI/CD pipeline.
src/lib.py
: Python script that contain all needed functionsmain.py
: Python script based on the functions of the lib and perform analtyical operationstest_main.py
: Contains tests to validate the operations..github/workflows/
: CI/CD pipeline configuration for automated testing.
- Python 3.x
- SQLite3 or any SQL database
sqlite3
library: Comes pre-installed with Pythonpytest
testing frameworkblack
code formatterruff
: for testing- GitHub Actions for continuous integration and delivery (CI/CD)
- Clone the repository:
git clone https://github.com/nogibjj/Ramil-Python-Script-interacting-with-SQL-Database.git cd Ramil-Python-Script-interacting-with-SQL-Database
- Install the required dependencies:
make install
- Format the code:
make format
- Lint the code:
make lint
- To test the scripts:
make test_file
- Run the Python script to connect to the SQL database and perform the operations:
python main.py
The script performs the following operations on the database:
- Create: Inserts new records into the database.
- Read: Queries the database and retrieves data.
- Update: Updates existing records.
- Delete: Removes records from the database.
The script includes at least two different SQL queries:
- Query 1: This SQL query retrieves information about the number of NBA players drafted in each year by their draft position.
- Query 2: This SQL query retrieves the average superstar rating of players by their position and draft year, but only includes combinations where the average superstar value is greater than 0.02.
A GitHub Actions CI/CD pipeline is configured to:
- Test the database connection.
- Ensure CRUD operations work correctly.
- Validate SQL queries.