{"id":19495301,"url":"https://github.com/edandresvan/practice-book-rust-web-development","last_synced_at":"2025-02-25T20:28:38.693Z","repository":{"id":155816034,"uuid":"564913347","full_name":"edandresvan/practice-book-rust-web-development","owner":"edandresvan","description":"Practical exercises from the book \"Rust Web Development\" by Bastian Gruber (Manning).","archived":false,"fork":false,"pushed_at":"2023-03-08T02:13:26.000Z","size":66,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-08T09:25:22.421Z","etag":null,"topics":["practice","practice-programming","programming","rust","rustlang"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edandresvan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-11T19:59:34.000Z","updated_at":"2023-01-06T17:11:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"cceaf54e-6e81-4bbb-9835-f2bb3714ada6","html_url":"https://github.com/edandresvan/practice-book-rust-web-development","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edandresvan%2Fpractice-book-rust-web-development","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edandresvan%2Fpractice-book-rust-web-development/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edandresvan%2Fpractice-book-rust-web-development/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edandresvan%2Fpractice-book-rust-web-development/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edandresvan","download_url":"https://codeload.github.com/edandresvan/practice-book-rust-web-development/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240740985,"owners_count":19850073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["practice","practice-programming","programming","rust","rustlang"],"created_at":"2024-11-10T21:36:54.395Z","updated_at":"2025-02-25T20:28:38.656Z","avatar_url":"https://github.com/edandresvan.png","language":"Rust","readme":"# Practice Book: Rust Web Development\n\n\nThis repository contains my practical exercises from the book [\"Rust Web Development\" by Bastian Gruber (Manning)](https://www.manning.com/books/rust-web-development).\n\n\n![Book Cover](https://images.manning.com/360/480/resize/book/9/57fa437-06ef-4a02-8070-bc33e0800c87/Gruber-HI.png)\n\nThe original code repository is also located [here in GitHub](https://github.com/Rust-Web-Development/code).\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n\n\nThe files in this repository are my own practice following the book lessons. \n\nHowever, the original copyright belongs to Manning Books.\n\nGruber, Bastian. 2023. Rust Web Development. Manning Publications. ISBN: \n978-1617299001\n\n## PostgreSQL Installation\n\nFrom chapter 7, a PostgreSQL database is used as the datastore for the web service of questions and answers. To install PostgreSQL using a [Podman](https://podman.io/) container and Ubuntu 22.10 follow these steps:\n\n### Install Podman\n\n```bash\n$ sudo apt-get install aptitude;\n$ sudo aptitude update \u0026\u0026 sudo aptitude upgrade -y;\n$ sudo aptitude install podman;\n```\n\n### Install PostgreSQL Clients\n\n```bash\n\n$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/postgresql.gpg;\n$ sudo sh -c 'echo \"deb [signed-by=/usr/share/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main\" \u003e /etc/apt/sources.list.d/postgresql.list';\n\n$ wget --quiet -O - https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/packages-pgadmin-org.gpg;\n\n$ sudo sh -c 'echo \"deb [signed-by=/usr/share/keyrings/packages-pgadmin-org.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main\" \u003e /etc/apt/sources.list.d/pgadmin4.list';\n \n$ sudo aptitude update \u0026\u0026 sudo aptitude upgrade -y;\n\n$ sudo aptitude install libpq-dev postgresql-client pgadmin4-desktop -y;\n```\n\n### Install a PostgreSQL Container\n\nGo to the source code directory for chapter 7 in this repository and ensure the SQL initialization script file to create the database is present:\n\n```bash\n$ cd ch07;\n$ ls ./docker-entrypoint-initdb.d;\n  init-db-rustwebdev.sh\n```\n\nWe will use the PostgreSQL container based on Debian Linux from the Docker Registry.\n\nCreate a disk volume (i.e. a directory) to persist the database we will maintain in the container.\n\n```bash\n$ podman volume create questionnaire_volume;\n```\n\nCreate the PostgreSQL container with the previously created disk volume and the customizable parameters. The first time, we specify the `POSTGRES_PASSWORD` parameter. Also the subdirectory with the initializaton script is mounted as a disk volume.\n\n```bash\n$ podman run --interactive --publish 5432:5432 --volume questionnaire_volume:/var/lib/postgresql/data --volume ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d --memory 500m --env POSTGRES_PASSWORD=myP4ssw0rd --name questionnaire docker.io/library/postgres:15-bullseye;\n```\n\n## Execute PostgreSQL Scripts\n\n### Sections 7.1 to 7.5\n\nUp to section 7.5, you can execute the SQL script `create-database.sql` to create the data structures.\n\n```bash\n$ cd db-scripts;\n$ psql --host=localhost --port=5432 --dbname=rustwebdev --username=firstdev --password --file=create-database.sql;\n\n```\n\n### Section 7.6 \nFrom section 7.6, you can work with SQL migrations. First, delete the existing data structures:\n\n```bash\n$ cd db-scripts;\n$ psql --host=localhost --port=5432 --dbname=rustwebdev --username=firstdev --password --file=drop-database.sql;\n\n```\n\nTo execute the `*-up` migrations scripts execute this command:\n\n```bash\nsqlx migrate run --database-url postgresql://firstdev:mypassword@localhost:5432/rustwebdev\n```\n\nTo execute the `*-down` migration scripts execute this command:\n\n```bash\nsqlx migrate revert --database-url postgresql://firstdev:mypassword@localhost:5432/rustwebdev\n```\n\nAdditionally, at the end of section 7.6 all `*-up` migrations will be executed when necessar before running the web application.\n\n```rust\n#[tokio::main]\nasync fn main() {\n  ...\n  sqlx::migrate!().run(\u0026store.clone().connection)\n  .await.expect(\"cannot run migration\");\n  \n  ...\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedandresvan%2Fpractice-book-rust-web-development","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedandresvan%2Fpractice-book-rust-web-development","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedandresvan%2Fpractice-book-rust-web-development/lists"}