试图理解.png

This commit is contained in:
shenjack 2024-09-06 06:17:44 +08:00
parent 40752741c1
commit 0eaaa544e9
Signed by: shenjack
GPG Key ID: 7B1134A979775551
4 changed files with 15 additions and 7 deletions

3
Cargo.lock generated
View File

@ -442,8 +442,10 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
dependencies = [ dependencies = [
"android-tzdata", "android-tzdata",
"iana-time-zone", "iana-time-zone",
"js-sys",
"num-traits", "num-traits",
"serde", "serde",
"wasm-bindgen",
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
@ -2595,6 +2597,7 @@ dependencies = [
"anyhow", "anyhow",
"axum", "axum",
"blake3", "blake3",
"chrono",
"colored", "colored",
"futures", "futures",
"migration", "migration",

View File

@ -36,3 +36,4 @@ serde = { version = "1.0", features = ["serde_derive"] }
toml = "0.8" toml = "0.8"
blake3 = "1.5.4" blake3 = "1.5.4"
quick-xml = { version = "0.36.1", features = ["async-tokio"] } quick-xml = { version = "0.36.1", features = ["async-tokio"] }
chrono = "0.4.38"

View File

@ -1,8 +1,8 @@
use blake3::Hasher; use blake3::Hasher;
use sea_orm::{ use sea_orm::{
ActiveModelTrait, ColumnTrait, ConnectionTrait, DatabaseConnection, EntityTrait, ActiveEnum, ActiveModelTrait, ColumnTrait, ConnectionTrait, DatabaseConnection, EntityTrait, IntoActiveModel, ModelTrait, QueryFilter, QuerySelect, Statement, TransactionTrait
IntoActiveModel, ModelTrait, QueryFilter, QuerySelect, Statement, TransactionTrait,
}; };
use tracing::{event, Level};
// use tracing::{event, Level}; // use tracing::{event, Level};
use crate::model; use crate::model;
@ -85,7 +85,7 @@ impl DbData {
/// 直接从 full_data 里选即可 /// 直接从 full_data 里选即可
pub async fn from_db(save_id: SaveId, db: &DatabaseConnection) -> Option<Self> { pub async fn from_db(save_id: SaveId, db: &DatabaseConnection) -> Option<Self> {
let sql = format!( let sql = format!(
"SELECT * FROM {} WHERE save_id = {}", "SELECT save_type::\"varchar\",* FROM {} WHERE save_id = {}",
FULL_DATA_VIEW, save_id FULL_DATA_VIEW, save_id
); );
let datas = db let datas = db
@ -96,14 +96,14 @@ impl DbData {
.await .await
.ok()??; .ok()??;
let text = datas.try_get("", "data").ok()?; let text = datas.try_get("", "data").ok()?;
let save_id: SaveId = datas.try_get("", "save_id").ok()?; let save_id: i32 = datas.try_get("", "save_id").ok()?;
let save_type: SaveType = datas.try_get("", "save_type").ok()?; let save_type: String = datas.try_get("", "save_type").ok()?;
let len: i64 = datas.try_get("", "len").ok()?; let len: i64 = datas.try_get("", "len").ok()?;
let blake_hash: String = datas.try_get("", "blake_hash").ok()?; let blake_hash: String = datas.try_get("", "blake_hash").ok()?;
Some(Self { Some(Self {
text, text,
save_id, save_id: save_id as SaveId,
save_type, save_type: SaveType::try_from_value(&save_type).unwrap(),
len, len,
blake_hash, blake_hash,
}) })
@ -156,6 +156,7 @@ where
// 干活之前, 先检查一下数据是否已经存在 // 干活之前, 先检查一下数据是否已经存在
// 如果已经存在, 那就根据策略来处理 // 如果已经存在, 那就根据策略来处理
let cover_strategy = cover_strategy.unwrap_or_default(); let cover_strategy = cover_strategy.unwrap_or_default();
let time = chrono::Utc::now();
let save_type: SaveType = save_type.into(); let save_type: SaveType = save_type.into();
let exitst_data: Option<model::main_data::Model> = { let exitst_data: Option<model::main_data::Model> = {
model::main_data::Entity::find() model::main_data::Entity::find()
@ -227,6 +228,7 @@ where
len: data_len as i64, len: data_len as i64,
short_data: None, short_data: None,
xml_tested, xml_tested,
time: time.into(),
}; };
let long_data = model::long_data::Model { let long_data = model::long_data::Model {
save_id: save_id as i32, save_id: save_id as i32,
@ -246,6 +248,7 @@ where
len: data_len as i64, len: data_len as i64,
short_data: Some(data), short_data: Some(data),
xml_tested, xml_tested,
time: time.into(),
}; };
new_data.into_active_model().insert(db).await?; new_data.into_active_model().insert(db).await?;
} }

View File

@ -13,6 +13,7 @@ pub struct Model {
pub len: i64, pub len: i64,
pub short_data: Option<String>, pub short_data: Option<String>,
pub xml_tested: Option<bool>, pub xml_tested: Option<bool>,
pub time: DateTimeWithTimeZone,
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]