refactor: 重构数据库插入参数结构体定义并移除重复及冗余前缀
- 重构代码以通过模块化导入使用InsertArgs结构体并移除重复定义。 - 优化数据库插入参数结构体定义并移除不必要的命名空间前缀以提升代码可读性和维护性。
This commit is contained in:
11
src/db.rs
11
src/db.rs
@@ -3,6 +3,8 @@ use serde::Serialize;
|
|||||||
use std::{fs, path::Path};
|
use std::{fs, path::Path};
|
||||||
use welds::{connections::sqlite::SqliteClient, prelude::*};
|
use welds::{connections::sqlite::SqliteClient, prelude::*};
|
||||||
|
|
||||||
|
use crate::InsertArgs;
|
||||||
|
|
||||||
#[derive(WeldsModel, Clone, Serialize)]
|
#[derive(WeldsModel, Clone, Serialize)]
|
||||||
#[welds(table = "authorize")]
|
#[welds(table = "authorize")]
|
||||||
pub struct Authorize {
|
pub struct Authorize {
|
||||||
@@ -16,15 +18,6 @@ pub struct Authorize {
|
|||||||
pub insert_time: String,
|
pub insert_time: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InsertArgs {
|
|
||||||
pub project: String,
|
|
||||||
pub token: String,
|
|
||||||
pub device_id: String,
|
|
||||||
pub disable: i8,
|
|
||||||
pub expire: String,
|
|
||||||
pub insert_time: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 包装类,内部持有 SQLite 连接
|
/// 包装类,内部持有 SQLite 连接
|
||||||
pub struct Db {
|
pub struct Db {
|
||||||
client: SqliteClient,
|
client: SqliteClient,
|
||||||
|
|||||||
11
src/main.rs
11
src/main.rs
@@ -72,7 +72,7 @@ async fn create_token(
|
|||||||
let token: String = state.generator.generate(16);
|
let token: String = state.generator.generate(16);
|
||||||
let _token_id = state
|
let _token_id = state
|
||||||
.db
|
.db
|
||||||
.insert_authorize(db::InsertArgs {
|
.insert_authorize(InsertArgs {
|
||||||
project: args.project.clone(),
|
project: args.project.clone(),
|
||||||
token: token.clone(),
|
token: token.clone(),
|
||||||
device_id: args.device_id.clone(),
|
device_id: args.device_id.clone(),
|
||||||
@@ -224,6 +224,15 @@ fn add_day(t: &str, days: i64) -> Result<String, ParseError> {
|
|||||||
Ok(new_time.format("%Y-%m-%d %H:%M:%S").to_string())
|
Ok(new_time.format("%Y-%m-%d %H:%M:%S").to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct InsertArgs {
|
||||||
|
pub project: String,
|
||||||
|
pub token: String,
|
||||||
|
pub device_id: String,
|
||||||
|
pub disable: i8,
|
||||||
|
pub expire: String,
|
||||||
|
pub insert_time: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct AppState {
|
struct AppState {
|
||||||
db: Arc<db::Db>,
|
db: Arc<db::Db>,
|
||||||
|
|||||||
Reference in New Issue
Block a user