refactor: 使用 returning 简化逻辑 (#488)
This commit is contained in:
@@ -60,6 +60,7 @@ sea-orm = { version = "1.1.17", features = [
|
||||
"macros",
|
||||
"runtime-tokio-rustls",
|
||||
"sqlx-sqlite",
|
||||
"sqlite-use-returning-for-3_35",
|
||||
] }
|
||||
sea-orm-migration = { version = "1.1.17", features = [] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::borrow::Cow;
|
||||
use std::path::Path;
|
||||
use std::pin::Pin;
|
||||
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use anyhow::{Result, ensure};
|
||||
use bili_sync_entity::rule::Rule;
|
||||
use bili_sync_entity::*;
|
||||
use chrono::Utc;
|
||||
@@ -94,21 +94,13 @@ impl VideoSource for collection::Model {
|
||||
collection_info,
|
||||
collection.collection
|
||||
);
|
||||
collection::ActiveModel {
|
||||
let updated_model = collection::ActiveModel {
|
||||
id: Unchanged(self.id),
|
||||
name: Set(collection_info.name.clone()),
|
||||
name: Set(collection_info.name),
|
||||
..Default::default()
|
||||
}
|
||||
.save(connection)
|
||||
.update(connection)
|
||||
.await?;
|
||||
Ok((
|
||||
collection::Entity::find()
|
||||
.filter(collection::Column::Id.eq(self.id))
|
||||
.one(connection)
|
||||
.await?
|
||||
.context("collection not found")?
|
||||
.into(),
|
||||
Box::pin(collection.into_video_stream()),
|
||||
))
|
||||
Ok((updated_model.into(), Box::pin(collection.into_video_stream())))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::borrow::Cow;
|
||||
use std::path::Path;
|
||||
use std::pin::Pin;
|
||||
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use anyhow::{Result, ensure};
|
||||
use bili_sync_entity::rule::Rule;
|
||||
use bili_sync_entity::*;
|
||||
use futures::Stream;
|
||||
@@ -63,21 +63,13 @@ impl VideoSource for favorite::Model {
|
||||
favorite_info.id,
|
||||
self.f_id
|
||||
);
|
||||
favorite::ActiveModel {
|
||||
let updated_model = favorite::ActiveModel {
|
||||
id: Unchanged(self.id),
|
||||
name: Set(favorite_info.title.clone()),
|
||||
name: Set(favorite_info.title),
|
||||
..Default::default()
|
||||
}
|
||||
.save(connection)
|
||||
.update(connection)
|
||||
.await?;
|
||||
Ok((
|
||||
favorite::Entity::find()
|
||||
.filter(favorite::Column::Id.eq(self.id))
|
||||
.one(connection)
|
||||
.await?
|
||||
.context("favorite not found")?
|
||||
.into(),
|
||||
Box::pin(favorite.into_video_stream()),
|
||||
))
|
||||
Ok((updated_model.into(), Box::pin(favorite.into_video_stream())))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::path::Path;
|
||||
use std::pin::Pin;
|
||||
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use anyhow::{Result, ensure};
|
||||
use bili_sync_entity::rule::Rule;
|
||||
use bili_sync_entity::*;
|
||||
use futures::Stream;
|
||||
@@ -62,21 +62,13 @@ impl VideoSource for submission::Model {
|
||||
upper.mid,
|
||||
submission.upper_id
|
||||
);
|
||||
submission::ActiveModel {
|
||||
let updated_model = submission::ActiveModel {
|
||||
id: Unchanged(self.id),
|
||||
upper_name: Set(upper.name),
|
||||
..Default::default()
|
||||
}
|
||||
.save(connection)
|
||||
.update(connection)
|
||||
.await?;
|
||||
Ok((
|
||||
submission::Entity::find()
|
||||
.filter(submission::Column::Id.eq(self.id))
|
||||
.one(connection)
|
||||
.await?
|
||||
.context("submission not found")?
|
||||
.into(),
|
||||
Box::pin(submission.into_video_stream()),
|
||||
))
|
||||
Ok((updated_model.into(), Box::pin(submission.into_video_stream())))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user