This project is a Rust application that interacts with a PostgreSQL database to manage authors and books. It demonstrates basic CRUD operations using the postgres crate.
- Rust and Cargo (See Rust Installation)
- Docker and Docker Compose (See Docker Installation)
- PostgreSQL client (Optional, for direct database interaction)
- Clone the repository:
git clone <repository-url>
cd <repository-directory>- Start the PostgreSQL database using Docker Compose:
docker-compose up -dThis command starts a PostgreSQL instance and an Adminer instance for database management accessible at http://localhost:8080.
- Run the application:
cd db-data
cargo runThis command compiles the Rust application and executes it, performing the defined database operations.
src/main.rs: Contains the main application logic for interacting with the PostgreSQL database.Cargo.toml: Contains the project metadata and dependencies.docker-compose.yml: Contains the configuration for the PostgreSQL and Adminer services.
The database schema consists of two tables:
authors: Contains the author information with the following columns:id: Unique identifier for the author.name: Name of the author.country: Country of the author.
books: Contains the book information with the following columns:id: Unique identifier for the book.title: Title of the book.author_id: Foreign key referencing theauthorstable.
The application provides a command-line interface (CLI) to interact with the database. The available commands are:
list-authors: List all authors in the database.create-author <name>: Create a new author with the given name.delete-author <id>: Delete the author with the given ID.list-books: List all books in the database.create-book <title> <author_id>: Create a new book with the given title and author ID.delete-book <id>: Delete the book with the given ID.help: Display the list of available commands.exit: Exit the application.
This project is licensed under the MIT License. See the LICENSE file for details.