Replies: 4 comments
-
pub mod model;
use std::thread::sleep;
use std::time::Duration;
use rbatis::intercept::SqlIntercept;
use rbatis::{crud, Error, Rbatis};
use rbatis::rbdc::datetime::FastDateTime;
use rbs::Value;
use crate::model::{init_db};
/// Logic delete: The deletion statement changes to the modification of flag, and the query statement filters flag with additional conditions
pub struct LogicDeletePlugin {}
impl SqlIntercept for LogicDeletePlugin {
fn do_intercept(&self, _rb: &Rbatis, sql: &mut String, _args: &mut Vec<Value>, _is_prepared_sql: bool) -> Result<(), Error> {
*sql=sql.replace("desc","'desc'");
Ok(())
}
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct UserGroup {
pub id: u64,
pub name: String,
pub desc: Option<String>,
pub ctime: FastDateTime,
}
rbatis::crud!(UserGroup {});
#[tokio::main]
pub async fn main() {
fast_log::init(fast_log::Config::new().console()).expect("rbatis init fail");
let mut rb = init_db().await;
rb.set_sql_intercepts(vec![Box::new(LogicDeletePlugin {})]);
let group1 = UserGroup {
id: 10,
name: String::from("group1"),
desc: None,
ctime: FastDateTime::now()
};
let data = UserGroup::insert(&mut rb, &group1).await;
println!("{:?}", data);
let r = UserGroup::select_by_column(&mut rb.clone(), "id", "1").await;
println!("{:?}", r);
sleep(Duration::from_secs(1));
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
pub mod model;
use std::thread::sleep;
use std::time::Duration;
use rbatis::intercept::SqlIntercept;
use rbatis::{crud, Error, Rbatis};
use rbatis::rbdc::datetime::FastDateTime;
use rbs::Value;
use crate::model::{init_db};
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct UserGroup {
pub id: u64,
pub name: String,
#[serde(rename ="'desc'")]
pub desc: Option<String>,
pub ctime: FastDateTime,
}
rbatis::crud!(UserGroup {});
#[tokio::main]
pub async fn main() {
fast_log::init(fast_log::Config::new().console()).expect("rbatis init fail");
let mut rb = init_db().await;
let group1 = UserGroup {
id: 10,
name: String::from("group1"),
desc: None,
ctime: FastDateTime::now()
};
let data = UserGroup::insert(&mut rb, &group1).await;
println!("{:?}", data);
let r = UserGroup::select_by_column(&mut rb.clone(), "id", "1").await;
println!("{:?}", r);
sleep(Duration::from_secs(1));
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi, Thanks a lot for the solutions! From the framework perspective, I think quote all fileds are definitely a better solution since you never know what users will input. BR, |
Beta Was this translation helpful? Give feedback.
0 replies
-
I had this same problem due to a table name of "transaction". I'm glad @gusvny posted something about this issue as the error message wouldn't have led me to the issue without seeing this post |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I accidentally use this "desc" as field name, then not able to insert data. Perhaps we can quote the field name in the insert sql statement and also other statements?
Beta Was this translation helpful? Give feedback.
All reactions