Lab realized as a student at ECN. This app is a python CLI (command line interface) to query a PostgreSQL database. https://github.com/DricomDragon/PythonPostgresLab

DricomDragon 861878cdd5 License unedr GNU GPLv3 vor 3 Jahren
SQL 7b62657022 Remove useless GRANT statement in db creation vor 5 Jahren
cli c7f03d6874 Regex validator added for quantity input vor 5 Jahren
consumer 7af9b333e5 Change credentials file to use python_app user vor 5 Jahren
model 9593f54ac1 Feature 'list warehouses' implemented vor 5 Jahren
.gitignore bad4ff78b1 Initial commit vor 5 Jahren
LICENSE.txt 861878cdd5 License unedr GNU GPLv3 vor 3 Jahren
README.md 861878cdd5 License unedr GNU GPLv3 vor 3 Jahren
app_customer.py e3bd76ea25 Quantity to type for each product in the new order vor 5 Jahren
app_dispatcher.py 8088fd5c08 New global display method to print not implemented features vor 5 Jahren
app_product.py 8088fd5c08 New global display method to print not implemented features vor 5 Jahren
basic_display.py 8088fd5c08 New global display method to print not implemented features vor 5 Jahren
python_postgres.png 422b059a0e Add logo vor 3 Jahren
test_pyinquirer.py 983c648b55 New script without sql to test pyinquirer vor 5 Jahren

README.md

PythonPostgresLab

A CLI (Command Line Interface) written in python to query a PostgreSQL database. Lab realized as a student at Ecole Centrale de Nantes (ECN).

PythonPostgresLab logo

Prerequisites

What you need to get this project running. These commands were tested on a debian based system (Ubuntu 18.04 LTS).

Python packages

Pip

If not installed yet, you need to get pip, the python package manager :

sudo apt install python3-pip

PyInquirer

For easy CLI python interfaces :

sudo pip3 install pyinquirer

Postgres

To install PostgreSQL driver :

sudo pip3 install postgres

PostgreSQL database

I strongly recommand to know how to run an instance of postgreSQL. The schema is a model of a logistics company.

Install a postgreSQL instance

Install postgreSQL :

sudo apt install postgresql

Start service :

sudo service postgresql start

Create SQL objects

Create python user

Create owner of the logistics database.

sudo -u postgres psql -f SQL/create_user.sql

Create the database

Create the database :

sudo -u postgres psql -f SQL/create_db.sql

Create tables

Populate database with tables :

sudo -u postgres psql -d logistics -f SQL/create_tables.sql

Grant python to alter these tables :

sudo -u postgres psql -d logistics -f SQL/grant_python.sql

Add starter testing data

Populate tables with sample data :

sudo -u postgres psql -d logistics -f SQL/populate_tables.sql

Security

If needed you can adapt the password of python_app user (or any user you want) :

sudo -u postgres psql -c "ALTER USER python_app PASSWORD 'blablapoivron'"

Do not forget to adapt the password in the consumer/credentials.py file.

Shortcut

To do everything in two single command : sudo -u postgres psql -f SQL/create_user.sql -f SQL/create_db.sql

sudo -u postgres psql -d logistics -f SQL/create_tables.sql -f SQL/grant_python.sql -f SQL/populate_tables.sql

Clear everything

Remove database and python_app db user :

sudo -u postgres psql -f SQL/clear_all.sql

Repository structure

How files are organized.

Python files with app_ prefix

Python application launched by user. For instance, to run the application as a customer, run the following command

python3 app_customer.py

test_pyinquirer.py

Execute this file with python to check if PyInquirer is correctly installed. No need of PostgreSQL to start this file.

basic_display.py

Contains a class that perform simple prints to show information to users.

cli

cli stands for command line interface. You will find every class which asks inputs to user. That's where the PyInquirer module is used.

consumer

Contains code to interact with the database. The class Consumer in consumer.py holds a connection to perform SQL queries against the database. If you need to change the credentials used to log on the database, please modify credentials.py.

SQL

Contains the SQL files used in the prerequisites section to create and populate the logistics database used by application.

model

Contain simple python classes mapped to relational model. Used in basic_display.py to get the code more readable.

License

GNU GPLv3. See LICENSE.txt.