Skip to content

Commit 4fc8c78

Browse files
committed
chore: refactored offline sqlx
1 parent 78aea5e commit 4fc8c78

File tree

4 files changed

+66
-118
lines changed

4 files changed

+66
-118
lines changed

Diff for: Cargo.lock

+56-53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1-13
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,7 @@ tracing-bunyan-formatter = "0.3.3"
2525
tracing-log = "0.1"
2626
secrecy = { version = "0.8", features = ["serde"] }
2727
tracing-actix-web = "0.5"
28-
29-
[dependencies.sqlx]
30-
version = "0.6.3"
31-
default-features = false
32-
features = [
33-
"runtime-actix-rustls",
34-
"macros",
35-
"postgres",
36-
"uuid",
37-
"chrono",
38-
"offline",
39-
"migrate"
40-
]
28+
sqlx = { version = "0.5.7", default-features = false, features = ["offline", "runtime-actix-rustls", "macros", "postgres", "uuid", "chrono", "migrate"] }
4129

4230
[dev-dependencies]
4331
reqwest = "0.11.18"

Diff for: sqlx-data.json

+5-50
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,18 @@
11
{
22
"db": "PostgreSQL",
3-
"8331e19e367a63b0c2112d1d8c048dd1a5f0eaa49d265d407a6ffd9469f127ce": {
4-
"query": "INSERT INTO subscription_tokens (subscription_token, subscriber_id) VALUES ($1, $2)",
5-
"describe": {
6-
"columns": [],
7-
"parameters": {
8-
"Left": [
9-
"Text",
10-
"Uuid"
11-
]
12-
},
13-
"nullable": []
14-
}
15-
},
16-
"a71a1932b894572106460ca2e34a63dc0cb8c1ba7a70547add1cddbb68133c2b": {
17-
"query": "UPDATE subscriptions SET status = 'confirmed' WHERE id = $1",
18-
"describe": {
19-
"columns": [],
20-
"parameters": {
21-
"Left": [
22-
"Uuid"
23-
]
24-
},
25-
"nullable": []
26-
}
27-
},
28-
"ad120337ee606be7b8d87238e2bb765d0da8ee61b1a3bc142414c4305ec5e17f": {
29-
"query": "SELECT subscriber_id FROM subscription_tokens WHERE subscription_token = $1",
30-
"describe": {
31-
"columns": [
32-
{
33-
"ordinal": 0,
34-
"name": "subscriber_id",
35-
"type_info": "Uuid"
36-
}
37-
],
38-
"parameters": {
39-
"Left": [
40-
"Text"
41-
]
42-
},
43-
"nullable": [
44-
false
45-
]
46-
}
47-
},
48-
"e6822c9e162eabc20338cc27d51a8e80578803ec1589c234d93c3919d14a96a6": {
49-
"query": "\n INSERT INTO subscriptions (id, email, name, subscribed_at, status)\n VALUES ($1, $2, $3, $4, 'pending_confirmation')\n ",
3+
"bcfcfebc6f5e8ffbf97d97c5a209be78b46d703924482cf8b43842705fcb7714": {
504
"describe": {
515
"columns": [],
6+
"nullable": [],
527
"parameters": {
538
"Left": [
549
"Uuid",
5510
"Text",
5611
"Text",
5712
"Timestamptz"
5813
]
59-
},
60-
"nullable": []
61-
}
14+
}
15+
},
16+
"query": "\n INSERT INTO subscriptions (id, email, name, subscribed_at)\n VALUES ($1, $2, $3, $4)\n "
6217
}
6318
}

Diff for: src/routes/subscriptions.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use actix_web::{web, HttpResponse};
22
use chrono::Utc;
33
use sqlx::PgPool;
4-
use uuid::Uuid;
4+
use sqlx::types::Uuid;
5+
// use uuid::Uuid;
56

67
#[allow(dead_code)]
78
#[derive(serde::Deserialize)]
@@ -34,12 +35,13 @@ pub async fn subscribe(form: web::Form<FormData>, pool: web::Data<PgPool>) -> Ht
3435
skip(form, pool),
3536
)]
3637
async fn insert_subscriber(form: &FormData, pool: &PgPool) -> Result<(), sqlx::Error> {
38+
let subscribe_id = Uuid::new_v4();
3739
sqlx::query!(
3840
r#"
3941
INSERT INTO subscriptions (id, email, name, subscribed_at)
4042
VALUES ($1, $2, $3, $4)
4143
"#,
42-
Uuid::new_v4(),
44+
subscribe_id,
4345
form.email,
4446
form.name,
4547
Utc::now()

0 commit comments

Comments
 (0)