Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf0872e3

Browse files
committed
add check intercept
1 parent391c72e commitf0872e3

File tree

7 files changed

+92
-9
lines changed

7 files changed

+92
-9
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::collections::HashMap;
2+
use proc_macro2::TokenStream;
3+
use quote::quote;
4+
usecrate::codegen::loader_html::Element;
5+
usecrate::codegen::syntax_tree_html::{HtmlAstNode,NodeContext,};
6+
7+
#[derive(Debug,Clone)]
8+
pubstructReturnNode{
9+
pubattrs:HashMap<String,String>,
10+
pubchilds:Vec<Element>,
11+
}
12+
implHtmlAstNodeforReturnNode{
13+
fnnode_tag_name() ->&'staticstr{"return"}
14+
15+
fnfrom_element(element:&Element) ->Self{
16+
// No specific attributes to extract for <otherwise> itself beyond common ones.
17+
Self{
18+
attrs: element.attrs.clone(),
19+
childs: element.childs.clone(),
20+
}
21+
}
22+
23+
fngenerate_tokens<FChildParser>(&self,context:&mutNodeContext<FChildParser>,ignore:&mutVec<String>) ->TokenStream
24+
where
25+
FChildParser:FnMut(&[Element],&mutTokenStream,&mutVec<String>,&str) ->TokenStream,
26+
{
27+
28+
let child_body = context.parse_children(&self.childs, ignore);
29+
30+
quote!{
31+
#child_body
32+
return(sql, args);
33+
}
34+
}
35+
}

‎src/crud.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ macro_rules! impl_select {
182182
trim ' and ': for key,item in condition:
183183
if !item.is_array():
184184
` and ${key.operator_sql()}#{item}`
185-
if item.is_array() && !item.is_empty():
185+
if item.is_array():
186186
` and ${key} in (`
187187
trim ',': for _,item_array in item:
188188
#{item_array},
@@ -248,7 +248,7 @@ macro_rules! impl_update {
248248
trim ' and ': for key,item in condition:
249249
if !item.is_array():
250250
` and ${key.operator_sql()}#{item}`
251-
if item.is_array() && !item.is_empty():
251+
if item.is_array():
252252
` and ${key} in (`
253253
trim ',': for _,item_array in item:
254254
#{item_array},
@@ -321,7 +321,7 @@ macro_rules! impl_delete {
321321
trim ' and ': for key,item in condition:
322322
if !item.is_array():
323323
` and ${key.operator_sql()}#{item}`
324-
if item.is_array() && !item.is_empty():
324+
if item.is_array():
325325
` and ${key} in (`
326326
trim ',': for _,item_array in item:
327327
#{item_array},

‎src/plugin/intercept.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ pub trait Intercept: Any + Send + Sync + Debug {
5959
/// task_id maybe is conn_id or tx_id,
6060
/// is_prepared_sql = !args.is_empty(),
6161
///
62-
/// if return None will be return result
63-
/// if return Some(true) will be run next intercept
64-
/// if return Some(false) will be break
62+
/// if returnOk(None) will be return result
63+
/// if returnOk(Some(true)) will be run next intercept
64+
/// if returnOk(Some(false)) will be break
6565
asyncfnbefore(
6666
&self,
6767
_task_id:i64,

‎src/plugin/intercept_check.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use async_trait::async_trait;
2+
use rbdc::db::ExecResult;
3+
use rbs::Value;
4+
usecrate::Error;
5+
usecrate::executor::Executor;
6+
usecrate::intercept::{Intercept,ResultType};
7+
8+
#[derive(Debug)]
9+
pubstructCheckIntercept{
10+
11+
}
12+
13+
implCheckIntercept{
14+
pubfnnew() ->CheckIntercept{
15+
CheckIntercept{}
16+
}
17+
}
18+
19+
#[async_trait]
20+
implInterceptforCheckIntercept{
21+
asyncfnbefore(
22+
&self,
23+
_task_id:i64,
24+
_executor:&dynExecutor,
25+
sql:&mutString,
26+
_args:&mutVec<Value>,
27+
result:ResultType<&mutResult<ExecResult,Error>,&mutResult<Vec<Value>,Error>>,
28+
) ->Result<Option<bool>,Error>{
29+
//check in empty array
30+
if sql.contains(" in ()"){
31+
match result{
32+
ResultType::Exec(exec) =>{
33+
*exec =Ok(ExecResult{
34+
rows_affected:0,
35+
last_insert_id:Default::default(),
36+
});
37+
}
38+
ResultType::Query(query) =>{
39+
*query =Ok(vec![]);
40+
}
41+
}
42+
returnOk(None);
43+
}
44+
Ok(Some(true))
45+
}
46+
}

‎src/plugin/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pubmod intercept;
22
pubmod intercept_log;
33
pubmod intercept_page;
4+
pubmod intercept_check;
45
pubmod object_id;
56
pubmod page;
67
pubmod snowflake;

‎src/rbatis.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::fmt::Debug;
1616
use std::ops::Deref;
1717
use std::sync::{Arc,OnceLock};
1818
use std::time::Duration;
19+
usecrate::intercept_check::CheckIntercept;
1920

2021
/// RBatis engine
2122
#[derive(Clone,Debug)]
@@ -45,8 +46,8 @@ impl RBatis {
4546
let rb =RBatis::default();
4647
//default use LogInterceptor
4748
rb.intercepts.push(Arc::new(PageIntercept::new()));
48-
rb.intercepts
49-
.push(Arc::new(LogInterceptor::new(LevelFilter::Debug)));
49+
rb.intercepts.push(Arc::new(LogInterceptor::new(LevelFilter::Debug)));
50+
rb.intercepts.push(Arc::new(CheckIntercept::new()));
5051
rb
5152
}
5253

‎tests/crud_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ mod test {
814814
println!("{}", sql);
815815
assert_eq!(
816816
sql.trim(),
817-
"select * from mock_table"
817+
"select * from mock_table where ids in ()"
818818
);
819819
assert_eq!(args, vec![]);
820820
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp