py lang support index parse
@@ -2,12 +2,8 @@ use std::collections::HashMap;
use std::hash::Hash;
use std::ops::Index;
use std::sync::{Mutex, RwLock};
-
use serde_json::json;
use serde_json::Value;
-
-use rbatis_core::db::DriverType;
-
use crate::ast::ast::RbatisAST;
use crate::ast::node::bind_node::BindNode;
use crate::ast::node::choose_node::ChooseNode;
@@ -21,8 +17,6 @@ use crate::ast::node::trim_node::TrimNode;
use crate::ast::node::when_node::WhenNode;
use crate::ast::node::where_node::WhereNode;
use crate::engine::parser::parse;
-use crate::engine::runtime::RbatisEngine;
-use crate::utils::bencher::Bencher;
lazy_static! {
static ref PY_PARSER_MAP: RwLock<HashMap<String,Vec<NodeType>>> = RwLock::new(HashMap::new());
@@ -188,11 +182,20 @@ impl Py {
trim_x = trim_x["for ".len()..].trim();
let in_index = trim_x.find(" in ").unwrap();
let col = trim_x[in_index + " in ".len()..].trim();
- let item = trim_x[..in_index].trim();
+ let mut item = trim_x[..in_index].trim();
+ let mut index = "";
+ if item.contains(",") {
+ let items: Vec<&str> = item.split(",").collect();
+ if items.len() != 2 {
+ return Err(rbatis_core::Error::from(format!("[rbatis][py] parse fail 'for ,' must be 'for arg1,arg2 in ...',value:'{}'", x)));
+ }
+ index = items[0];
+ item = items[1];
+ }
return Ok(NodeType::NForEach(ForEachNode {
childs: vec![],
collection: col.to_string(),
- index: "".to_string(),
+ index: index.to_string(),
item: item.to_string(),
open: "".to_string(),
close: "".to_string(),
@@ -317,6 +320,12 @@ impl Py {
}
}
+#[cfg(test)]
+mod test{
+ use crate::ast::lang::py::Py;
+ use rbatis_core::db::DriverType;
+ use crate::engine::runtime::RbatisEngine;
+ use crate::utils::bencher::Bencher;
#[test]
pub fn test_py_interpreter_parse() {
@@ -332,6 +341,8 @@ pub fn test_py_interpreter_parse() {
yes
for item in ids:
#{item}
+ for index,item in ids:
+ #{item}
trim 'AND':
AND delete_flag = #{del2}
WHERE id = '2';";
@@ -402,3 +413,4 @@ pub fn bench_exec() {
|| s.ends_with("/");
});
}
+}
\ No newline at end of file
