This commit is contained in:
Zengtudor 2024-07-22 00:16:00 +08:00
parent 3383dcaffa
commit 5a6b6fa0bc
2 changed files with 6 additions and 5 deletions

View File

@ -33,7 +33,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
} }
}; };
info!("parsed object Ok!"); info!("parsed object Ok!Vec.size={}",parsed_object.len());
info!("object[0]={:?}",parsed_object[0]); info!("object[0]={:?}",parsed_object[0]);
let mut word_orm_obj:Vec<word_entity::Model>=vec![]; let mut word_orm_obj:Vec<word_entity::Model>=vec![];
@ -44,8 +44,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
word_entity::add_to_database(word_orm_obj, &db_info.conn) word_entity::add_to_database(word_orm_obj, &db_info.conn)
.await .await
.map_err(|e|{error!("add to database error");error!("{}",e);exit(1)}) .unwrap_or_else(|e: Box<dyn Error>|{error!("add to database error");error!("{}",e);exit(1)});
.unwrap();
return Ok(()); return Ok(());
} }

View File

@ -1,6 +1,6 @@
use log::info; use log::info;
use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseConnection}; use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseConnection};
use std::error::Error; use std::{error::Error, time::Duration};
use sea_orm::Schema; use sea_orm::Schema;
pub struct Starter { pub struct Starter {
@ -8,7 +8,9 @@ pub struct Starter {
} }
impl Starter { impl Starter {
pub async fn connect(db_url:&str) -> Result<Self, Box<dyn Error>> { pub async fn connect(db_url:&str) -> Result<Self, Box<dyn Error>> {
let opt: ConnectOptions = ConnectOptions::new(db_url); let mut opt: ConnectOptions = ConnectOptions::new(db_url);
opt.connect_timeout(Duration::from_secs(360));
let conn_new: DatabaseConnection = Database::connect(opt).await?; let conn_new: DatabaseConnection = Database::connect(opt).await?;
Ok(Starter{conn:conn_new}) Ok(Starter{conn:conn_new})