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