Skip to content

Commit

Permalink
fix: db dependencies + dependencies update (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
piny4man committed Jan 13, 2024
1 parent 3f3ba3b commit 31e5123
Show file tree
Hide file tree
Showing 18 changed files with 899 additions and 767 deletions.
1,539 changes: 835 additions & 704 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
[workspace]
members = [
"api/lib",
"api/actix",
"api/shuttle",
"front",
"shared"
]
members = ["api/lib", "api/actix", "api/shuttle", "front", "shared"]
resolver = "2"

[workspace.dependencies]
# internal
Expand All @@ -14,7 +9,14 @@ api-lib = { version = "0.1.0", path = "./api/lib" }
# actix and sqlx
actix-web = "4.3.1"
actix-files = "0.6.2"
sqlx = { version = "0.6.3", default-features = false, features = [ "runtime-actix-native-tls", "macros", "postgres", "uuid", "chrono", "json" ] }
sqlx = { version = "0.7", default-features = false, features = [
"tls-native-tls",
"macros",
"postgres",
"uuid",
"chrono",
"json",
] }
# serde
serde = { version = "1.0.164", features = ["derive"] }
# utils
Expand Down
9 changes: 4 additions & 5 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# project tasks
[tasks.api-run]
workspace = false
env = { RUST_LOG="info" }
env = { RUST_LOG = "info" }
install_crate = "cargo-shuttle"
command = "cargo"
args = ["shuttle", "run"]
Expand All @@ -15,7 +15,7 @@ args = ["run", "--bin", "api-actix"]
workspace = false
cwd = "./front"
install_crate = "dioxus-cli"
command = "dioxus"
command = "dx"
args = ["serve", "--port", "8000"]

[tasks.front-build]
Expand All @@ -28,8 +28,8 @@ rm -rf api/shuttle/static static
mkdir api/shuttle/static
mkdir static
cd front
dioxus build --release
# local development
dx build --release
# local development
cp -r dist/* ../api/shuttle/static
# production
cp -r dist/* ../static
Expand Down Expand Up @@ -100,4 +100,3 @@ cwd = "./docs"
install_crate = "mdbook"
command = "mdbook"
args = ["serve"]

2 changes: 1 addition & 1 deletion api/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ tracing = { workspace = true }

[dev-dependencies]
actix-rt = "2"
mockall = "0.11"
mockall = "0.12.1"
10 changes: 4 additions & 6 deletions api/shuttle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ publish = false
# internal
api-lib = { workspace = true }
# shuttle
shuttle-runtime = "0.21.0"
shuttle-actix-web = "0.21.0"
shuttle-runtime = "0.36.0"
shuttle-actix-web = "0.36.0"
# db
# shuttle-aws-rds = { version = "0.18.0", features = ["postgres"] }
shuttle-shared-db = { version = "0.21.0", features = ["postgres"] }
shuttle-shared-db = { version = "0.36.0", features = ["postgres"] }
sqlx = { workspace = true }
# static files
shuttle-static-folder = "0.21.0"
# actix
# actixs
actix-web = { workspace = true }
actix-files = { workspace = true }
tokio = "1.28.2"
10 changes: 2 additions & 8 deletions api/shuttle/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::path::PathBuf;

use actix_files::Files;
use actix_web::web::{self, ServiceConfig};
use shuttle_actix_web::ShuttleActixWeb;
use shuttle_runtime::CustomError;
Expand All @@ -8,7 +7,6 @@ use sqlx::Executor;
#[shuttle_runtime::main]
async fn actix_web(
#[shuttle_shared_db::Postgres()] pool: sqlx::PgPool,
#[shuttle_static_folder::StaticFolder(folder = "static")] static_folder: PathBuf,
) -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> {
// initialize the database if not already initialized
pool.execute(include_str!("../../db/schema.sql"))
Expand All @@ -29,11 +27,7 @@ async fn actix_web(
api_lib::v1::service::<api_lib::film_repository::PostgresFilmRepository>,
),
)
.service(
actix_files::Files::new("/", static_folder)
.show_files_listing()
.index_file("index.html"),
);
.service(Files::new("/", "static").index_file("index.html"));
};

Ok(config.into())
Expand Down
1 change: 1 addition & 0 deletions docs/src/backend/01_workspace_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ members = [
"api/shuttle",
"shared"
]
resolver = "2"
```

We will add the `front` crate later, don't worry.
Expand Down
11 changes: 9 additions & 2 deletions docs/src/backend/05_working_with_a_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ Go to the `Cargo.toml` file in the `api > shuttle` folder and add the following
[dependencies]
...
# database
shuttle-shared-db = { version = "0.21.0", features = ["postgres"] }
sqlx = { version = "0.6.3", default-features = false, features = [ "runtime-actix-native-tls", "macros", "postgres", "uuid", "chrono", "json" ] }
shuttle-shared-db = { version = "0.36.0", features = ["postgres"] }
sqlx = { version = "0.7", default-features = false, features = [
"tls-native-tls",
"macros",
"postgres",
"uuid",
"chrono",
"json",
] }
```

```admonish title="Cargo Dependencies"
Expand Down
9 changes: 8 additions & 1 deletion docs/src/backend/12_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ Now, if you compile, you should be getting errors from the compiler complaining
# actix
actix-web = "4.3.1"
# database
sqlx = { version = "0.6.3", default-features = false, features = [ "runtime-actix-native-tls", "macros", "postgres", "uuid", "chrono", "json" ] }
sqlx = { version = "0.7", default-features = false, features = [
"tls-native-tls",
"macros",
"postgres",
"uuid",
"chrono",
"json",
] }
# tracing
tracing = "0.1"
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/backend/19_film_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Let's bring this dependency into our `api-lib` crate by adding it to the `Cargo.
```diff
[dependencies]
+ # utils
+ async-trait = "0.1"
+ uuid = { version = "1.3", features = ["serde", "v4", "js"] }
+ async-trait = "0.1.68"
+ uuid = { version = "1.3.4", features = ["serde", "v4", "js"] }
```

Now, let's mark our [trait](https://doc.rust-lang.org/book/ch10-02-traits.html) as `async` and add all the `use` statements we need:
Expand Down
11 changes: 9 additions & 2 deletions docs/src/backend/20_implementing_trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl PostgresFilmRepository {
}
```

```admonish
```admonish
This sort of constructor pattern is very common in Rust and the convention is to use `new` as the name of the associated function.
```

Expand Down Expand Up @@ -154,7 +154,14 @@ Add the [SQLx](https://github.com/launchbadge/sqlx) dependency to the `Cargo.tom

```toml
# database
sqlx = { version = "0.6.3", default-features = false, features = [ "runtime-actix-native-tls", "macros", "postgres", "uuid", "chrono", "json" ] }
sqlx = { version = "0.7", default-features = false, features = [
"tls-native-tls",
"macros",
"postgres",
"uuid",
"chrono",
"json",
] }
```
And then add the `sqlx::FromRow` trait into the `derive` attribute of the `Film` and `CreateFilm` structs.
Expand Down
20 changes: 3 additions & 17 deletions docs/src/backend/24_serving_static_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ Let's add the `shuttle-static-folder` and the [actix-files](https://docs.rs/acti
[dependencies]
# static
actix-files = "0.6.2"
shuttle-static-folder = "0.21.0"
```

## Serving the static files

Now, let's refactor our `main.rs` file to serve the static files.

Add this parameter to the `actix_web` function:

```rust
#[shuttle_static_folder::StaticFolder(folder = "static")] static_folder: PathBuf,
```

And then, let's modify our `ServiceConfig` to serve static files in the `/` path and the API in the `/api` path:
Let's modify our `ServiceConfig` to serve static files in the `/` path and the API in the `/api` path:

```diff
- cfg.app_data(film_repository)
Expand All @@ -47,11 +41,7 @@ And then, let's modify our `ServiceConfig` to serve static files in the `/` path
+ api_lib::films::service::<api_lib::film_repository::PostgresFilmRepo+ sitory>,
+ ),
+ )
+ .service(
+ actix_files::Files::new("/", static_folder)
+ .show_files_listing()
+ .index_file("index.html"),
+ );
+ .service(Files::new("/", "static").index_file("index.html"));
```

~~~admonish tip title="Final Code" collapsible=true
Expand Down Expand Up @@ -84,11 +74,7 @@ async fn actix_web(
api_lib::films::service::<api_lib::film_repository::PostgresFilmRepository>,
),
)
.service(
actix_files::Files::new("/", static_folder)
.show_files_listing()
.index_file("index.html"),
);
.service(Files::new("/", "static").index_file("index.html"));
};
Ok(config.into())
Expand Down
4 changes: 2 additions & 2 deletions docs/src/frontend/03_01_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ Add Dioxus and the web renderer as dependencies to your project, modify your `Ca

[dependencies]
# dioxus
dioxus = "0.3.2"
dioxus-web = "0.3.2"
dioxus = "0.4.3"
dioxus-web = "0.4.3"
```

## Tailwind Configuration
Expand Down
6 changes: 3 additions & 3 deletions docs/src/frontend/03_02_app_startup.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ The first step towards this involves installing the `wasm-logger` crate. You can
...
[dependencies]
# dioxus
dioxus = "0.3.2"
dioxus-web = "0.3.2"
dioxus = "0.4.3"
dioxus-web = "0.4.3"
+log = "0.4.19"
+wasm-logger = "0.2.0"
```
Expand All @@ -123,4 +123,4 @@ With the logger initialized, you can now log messages to your browser's console.
log::info!("Message on my console");
```

By using this logging mechanism, you can make your debugging process more straightforward and efficient.
By using this logging mechanism, you can make your debugging process more straightforward and efficient.
4 changes: 2 additions & 2 deletions docs/src/frontend/03_04_02_local_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ Finally add `uuid` dependency to the `Cargo.toml` file.
# shared
shared = { path = "../shared" }
# dioxus
dioxus = "0.3.2"
dioxus-web = "0.3.2"
dioxus = "0.4.3"
dioxus-web = "0.4.3"
wasm-logger = "0.2.0"
+uuid = { version = "1.3.4", features = ["serde", "v4", "js"] }
```
4 changes: 2 additions & 2 deletions front/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ edition = "2021"
# shared
shared = { workspace = true }
# dioxus
dioxus = "0.3.2"
dioxus-web = "0.3.2"
dioxus = "0.4.3"
dioxus-web = "0.4.3"
reqwest = { version = "0.11.18", features = ["json"] }
serde = { workspace = true }
uuid = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dioxus::prelude::*;

use crate::models::ButtonType;

#[inline_props]
#[component]
pub fn Button<'a>(
cx: Scope<'a>,
button_type: ButtonType,
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/film_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{components::Button, models::ButtonType};
use dioxus::prelude::*;
use shared::models::Film;

#[inline_props]
#[component]
pub fn FilmCard<'a>(
cx: Scope<'a>,
film: &'a Film,
Expand Down

0 comments on commit 31e5123

Please sign in to comment.