1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00
examples/basics/todo/README.md

50 lines
1018 B
Markdown
Raw Normal View History

2022-02-06 08:55:51 +01:00
# Todo
2018-08-27 11:56:26 +02:00
2022-02-06 08:55:51 +01:00
A simple Todo project using a SQLite database.
2018-08-27 11:56:26 +02:00
## Prerequisites
2022-02-06 08:55:51 +01:00
- SQLite 3
2018-08-27 11:56:26 +02:00
2023-07-09 03:05:10 +02:00
## Change Into The Examples Workspace Root Directory
2018-08-27 11:56:26 +02:00
2023-07-09 03:05:10 +02:00
All instructions assume you have changed into the examples workspace root:
2018-08-27 11:56:26 +02:00
2023-07-09 03:05:10 +02:00
```pwd
$ pwd
.../examples
2018-08-27 11:56:26 +02:00
```
2022-02-06 08:55:51 +01:00
## Set Up The Database
2018-08-27 11:56:26 +02:00
2022-02-06 08:55:51 +01:00
Install the [sqlx](https://github.com/launchbadge/sqlx/tree/HEAD/sqlx-cli) command-line tool with the required features:
2018-08-27 11:56:26 +02:00
2022-02-06 08:55:51 +01:00
```sh
cargo install sqlx-cli --no-default-features --features=rustls,sqlite
2018-08-27 11:56:26 +02:00
```
Then to create and set-up the database run:
2022-02-06 08:55:51 +01:00
```sh
2022-02-05 18:34:43 +01:00
sqlx database create
sqlx migrate run
2018-08-27 11:56:26 +02:00
```
2022-02-06 08:55:51 +01:00
## Run The Application
2018-08-27 11:56:26 +02:00
2022-02-06 08:55:51 +01:00
Start the application with:
2018-08-27 11:56:26 +02:00
2022-02-06 08:55:51 +01:00
```sh
2023-07-09 03:05:10 +02:00
cargo run --bin=todo
2018-08-27 11:56:26 +02:00
```
2022-02-06 08:55:51 +01:00
The app will be viewable in the browser at <http://localhost:8080>.
## Modifying The Example Database
For simplicity, this example uses SQLx's offline mode. If you make any changes to the database schema, this must be turned off or the `sqlx-data.json` file regenerated using the following command:
```sh
2023-07-09 03:05:10 +02:00
cargo sqlx prepare --database-url=sqlite://./todo.db
2022-02-06 08:55:51 +01:00
```