Skip to content

Commit 2d17e90

Browse files
author
Glubus
committed
fix: making clippy happy :)
1 parent ab8cea7 commit 2d17e90

File tree

12 files changed

+94
-347
lines changed

12 files changed

+94
-347
lines changed

src/models/beatmap/impl.rs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,10 @@
11
use super::query::{exists_by_checksum, find_by_id, get_beatmapset_id, insert::insert};
22
use super::types::BeatmapRow;
3-
use bigdecimal::BigDecimal;
43
use sqlx::PgPool;
54

65
impl BeatmapRow {
7-
pub async fn insert_into_db(
8-
pool: &PgPool,
9-
osu_id: Option<i32>,
10-
beatmapset_id: Option<i32>,
11-
difficulty: String,
12-
difficulty_rating: BigDecimal,
13-
count_circles: i32,
14-
count_sliders: i32,
15-
count_spinners: i32,
16-
max_combo: i32,
17-
drain_time: i32,
18-
total_time: i32,
19-
bpm: BigDecimal,
20-
cs: BigDecimal,
21-
ar: BigDecimal,
22-
od: BigDecimal,
23-
hp: BigDecimal,
24-
mode: i32,
25-
status: String,
26-
file_md5: String,
27-
file_path: String,
28-
) -> Result<i32, sqlx::Error> {
29-
insert(
30-
pool,
31-
osu_id,
32-
beatmapset_id,
33-
difficulty,
34-
difficulty_rating,
35-
count_circles,
36-
count_sliders,
37-
count_spinners,
38-
max_combo,
39-
drain_time,
40-
total_time,
41-
bpm,
42-
cs,
43-
ar,
44-
od,
45-
hp,
46-
mode,
47-
status,
48-
file_md5,
49-
file_path,
50-
)
51-
.await
6+
pub async fn insert_into_db(self, pool: &PgPool) -> Result<i32, sqlx::Error> {
7+
insert(pool, self).await
528
}
539

5410
pub async fn find_by_id(pool: &PgPool, id: i32) -> Result<Option<Self>, sqlx::Error> {

src/models/beatmap/query/insert.rs

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
use bigdecimal::BigDecimal;
1+
use crate::models::beatmap::types::BeatmapRow;
22
use sqlx::{Error as SqlxError, PgPool};
33

4-
pub async fn insert(
5-
pool: &PgPool,
6-
osu_id: Option<i32>,
7-
beatmapset_id: Option<i32>,
8-
difficulty: String,
9-
difficulty_rating: BigDecimal,
10-
count_circles: i32,
11-
count_sliders: i32,
12-
count_spinners: i32,
13-
max_combo: i32,
14-
drain_time: i32,
15-
total_time: i32,
16-
bpm: BigDecimal,
17-
cs: BigDecimal,
18-
ar: BigDecimal,
19-
od: BigDecimal,
20-
hp: BigDecimal,
21-
mode: i32,
22-
status: String,
23-
file_md5: String,
24-
file_path: String,
25-
) -> Result<i32, SqlxError> {
4+
pub async fn insert(pool: &PgPool, beatmap: BeatmapRow) -> Result<i32, SqlxError> {
265
Ok(sqlx::query!(
276
r#"
287
INSERT INTO beatmap (
@@ -33,25 +12,25 @@ pub async fn insert(
3312
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19)
3413
RETURNING id
3514
"#,
36-
osu_id,
37-
beatmapset_id,
38-
difficulty,
39-
difficulty_rating,
40-
count_circles,
41-
count_sliders,
42-
count_spinners,
43-
max_combo,
44-
drain_time,
45-
total_time,
46-
bpm,
47-
cs,
48-
ar,
49-
od,
50-
hp,
51-
mode,
52-
status,
53-
file_md5,
54-
file_path
15+
beatmap.osu_id,
16+
beatmap.beatmapset_id,
17+
beatmap.difficulty,
18+
beatmap.difficulty_rating,
19+
beatmap.count_circles,
20+
beatmap.count_sliders,
21+
beatmap.count_spinners,
22+
beatmap.max_combo,
23+
beatmap.drain_time,
24+
beatmap.total_time,
25+
beatmap.bpm,
26+
beatmap.cs,
27+
beatmap.ar,
28+
beatmap.od,
29+
beatmap.hp,
30+
beatmap.mode,
31+
beatmap.status,
32+
beatmap.file_md5,
33+
beatmap.file_path
5534
)
5635
.fetch_one(pool)
5736
.await?

src/models/beatmapset/impl.rs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,8 @@ use super::types::BeatmapsetRow;
33
use sqlx::PgPool;
44

55
impl BeatmapsetRow {
6-
pub async fn insert(
7-
pool: &PgPool,
8-
osu_id: Option<i32>,
9-
artist: String,
10-
artist_unicode: Option<String>,
11-
title: String,
12-
title_unicode: Option<String>,
13-
creator: String,
14-
source: Option<String>,
15-
tags: Option<Vec<String>>,
16-
has_video: bool,
17-
has_storyboard: bool,
18-
is_explicit: bool,
19-
is_featured: bool,
20-
cover_url: Option<String>,
21-
preview_url: Option<String>,
22-
osu_file_url: Option<String>,
23-
) -> Result<i32, sqlx::Error> {
24-
insert(
25-
pool,
26-
osu_id,
27-
artist,
28-
artist_unicode,
29-
title,
30-
title_unicode,
31-
creator,
32-
source,
33-
tags,
34-
has_video,
35-
has_storyboard,
36-
is_explicit,
37-
is_featured,
38-
cover_url,
39-
preview_url,
40-
osu_file_url,
41-
)
42-
.await
6+
pub async fn insert(self, pool: &PgPool) -> Result<i32, sqlx::Error> {
7+
insert(pool, self).await
438
}
449

4510
pub async fn find_by_id(pool: &PgPool, id: i32) -> Result<Option<Self>, sqlx::Error> {

src/models/beatmapset/query/insert.rs

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
1+
use crate::models::beatmapset::types::BeatmapsetRow;
12
use sqlx::{Error as SqlxError, PgPool};
23

3-
pub async fn insert(
4-
pool: &PgPool,
5-
osu_id: Option<i32>,
6-
artist: String,
7-
artist_unicode: Option<String>,
8-
title: String,
9-
title_unicode: Option<String>,
10-
creator: String,
11-
source: Option<String>,
12-
tags: Option<Vec<String>>,
13-
has_video: bool,
14-
has_storyboard: bool,
15-
is_explicit: bool,
16-
is_featured: bool,
17-
cover_url: Option<String>,
18-
preview_url: Option<String>,
19-
osu_file_url: Option<String>,
20-
) -> Result<i32, SqlxError> {
4+
pub async fn insert(pool: &PgPool, beatmapset: BeatmapsetRow) -> Result<i32, SqlxError> {
215
Ok(sqlx::query!(
226
r#"
237
INSERT INTO beatmapset (
@@ -43,21 +27,21 @@ pub async fn insert(
4327
updated_at = now()
4428
RETURNING id
4529
"#,
46-
osu_id,
47-
artist,
48-
artist_unicode.as_deref(),
49-
title,
50-
title_unicode.as_deref(),
51-
creator,
52-
source.as_deref(),
53-
tags.as_deref(),
54-
has_video,
55-
has_storyboard,
56-
is_explicit,
57-
is_featured,
58-
cover_url.as_deref(),
59-
preview_url.as_deref(),
60-
osu_file_url.as_deref()
30+
beatmapset.osu_id,
31+
beatmapset.artist,
32+
beatmapset.artist_unicode.as_deref(),
33+
beatmapset.title,
34+
beatmapset.title_unicode.as_deref(),
35+
beatmapset.creator,
36+
beatmapset.source.as_deref(),
37+
beatmapset.tags.as_deref(),
38+
beatmapset.has_video,
39+
beatmapset.has_storyboard,
40+
beatmapset.is_explicit,
41+
beatmapset.is_featured,
42+
beatmapset.cover_url.as_deref(),
43+
beatmapset.preview_url.as_deref(),
44+
beatmapset.osu_file_url.as_deref()
6145
)
6246
.fetch_one(pool)
6347
.await?

src/models/msd/impl.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,11 @@ use super::query::{
22
find_all_by_beatmap_id, find_by_beatmap_id, find_by_beatmap_id_and_rate, find_by_id, insert,
33
};
44
use super::types::MSDRow;
5-
use bigdecimal::BigDecimal;
65
use sqlx::PgPool;
76

87
impl MSDRow {
9-
pub async fn insert_into_db(
10-
pool: &PgPool,
11-
beatmap_id: i32,
12-
overall: BigDecimal,
13-
stream: BigDecimal,
14-
jumpstream: BigDecimal,
15-
handstream: BigDecimal,
16-
stamina: BigDecimal,
17-
jackspeed: BigDecimal,
18-
chordjack: BigDecimal,
19-
technical: BigDecimal,
20-
rate: BigDecimal,
21-
main_pattern: Option<String>,
22-
) -> Result<i32, sqlx::Error> {
23-
insert(
24-
pool,
25-
beatmap_id,
26-
overall,
27-
stream,
28-
jumpstream,
29-
handstream,
30-
stamina,
31-
jackspeed,
32-
chordjack,
33-
technical,
34-
rate,
35-
main_pattern,
36-
)
37-
.await
8+
pub async fn insert_into_db(self, pool: &PgPool) -> Result<i32, sqlx::Error> {
9+
insert(pool, self).await
3810
}
3911

4012
pub async fn find_by_id(pool: &PgPool, id: i32) -> Result<Option<Self>, sqlx::Error> {

src/models/msd/query/insert.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
use bigdecimal::BigDecimal;
1+
use crate::models::msd::types::MSDRow;
22

33
use sqlx::{Error as SqlxError, PgPool};
44

5-
pub async fn insert(
6-
pool: &PgPool,
7-
beatmap_id: i32,
8-
overall: BigDecimal,
9-
stream: BigDecimal,
10-
jumpstream: BigDecimal,
11-
handstream: BigDecimal,
12-
stamina: BigDecimal,
13-
jackspeed: BigDecimal,
14-
chordjack: BigDecimal,
15-
technical: BigDecimal,
16-
rate: BigDecimal,
17-
main_pattern: Option<String>,
18-
) -> Result<i32, SqlxError> {
5+
pub async fn insert(pool: &PgPool, msd: MSDRow) -> Result<i32, SqlxError> {
196
let row = sqlx::query!(
207
r#"
218
INSERT INTO msd (
@@ -24,17 +11,17 @@ pub async fn insert(
2411
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)
2512
RETURNING id
2613
"#,
27-
beatmap_id,
28-
overall,
29-
stream,
30-
jumpstream,
31-
handstream,
32-
stamina,
33-
jackspeed,
34-
chordjack,
35-
technical,
36-
rate,
37-
main_pattern
14+
msd.beatmap_id,
15+
msd.overall,
16+
msd.stream,
17+
msd.jumpstream,
18+
msd.handstream,
19+
msd.stamina,
20+
msd.jackspeed,
21+
msd.chordjack,
22+
msd.technical,
23+
msd.rate,
24+
msd.main_pattern
3825
)
3926
.fetch_one(pool)
4027
.await?;
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use sqlx::{Error as SqlxError, PgPool};
22

33
pub async fn count(pool: &PgPool) -> Result<i64, SqlxError> {
4-
Ok(
5-
sqlx::query_scalar::<_, i64>(r#"SELECT COUNT(*) FROM pending_beatmap"#)
6-
.fetch_one(pool)
7-
.await?,
8-
)
4+
sqlx::query_scalar::<_, i64>(r#"SELECT COUNT(*) FROM pending_beatmap"#)
5+
.fetch_one(pool)
6+
.await
97
}

src/models/score/impl.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,11 @@ use super::query::{
88
update_status::{update_status, update_status_by_hash},
99
};
1010
use super::types::ScoreRow;
11-
use bigdecimal::BigDecimal;
1211
use sqlx::PgPool;
1312

1413
impl ScoreRow {
15-
pub async fn insert(
16-
pool: &PgPool,
17-
user_id: i64,
18-
beatmap_id: i32,
19-
score_metadata_id: i32,
20-
replay_id: Option<i32>,
21-
rate: BigDecimal,
22-
hwid: Option<&str>,
23-
mods: i64,
24-
hash: &str,
25-
rank: &str,
26-
status: &str,
27-
) -> Result<Self, sqlx::Error> {
28-
insert(
29-
pool,
30-
user_id,
31-
beatmap_id,
32-
score_metadata_id,
33-
replay_id,
34-
rate,
35-
hwid,
36-
mods,
37-
hash,
38-
rank,
39-
status,
40-
)
41-
.await
14+
pub async fn insert(self, pool: &PgPool) -> Result<Self, sqlx::Error> {
15+
insert(pool, self).await
4216
}
4317

4418
pub async fn exists_by_hash(pool: &PgPool, hash: &str) -> Result<bool, sqlx::Error> {

0 commit comments

Comments
 (0)