@@ -108,11 +108,11 @@ macro_rules! impl_insert {
108
108
"insert can not insert empty array tables!" ,
109
109
) ) ;
110
110
}
111
- #[ $crate:: snake_name( $table) ]
112
- fn snake_name( ) { }
113
111
let mut table_name = $table_name. to_string( ) ;
114
- if table_name. is_empty( ) {
115
- table_name = snake_name( ) ;
112
+ if table_name. is_empty( ) {
113
+ #[ $crate:: snake_name( $table) ]
114
+ fn snake_name( ) { }
115
+ table_name = snake_name( ) ;
116
116
}
117
117
let mut result = $crate:: rbdc:: db:: ExecResult {
118
118
rows_affected: 0 ,
@@ -176,8 +176,12 @@ macro_rules! impl_select {
176
176
} ;
177
177
( $table: ty{ } , $table_name: expr) =>{
178
178
$crate:: impl_select!( $table{ select_all( ) =>"" } , $table_name) ;
179
- $crate:: impl_select!( $table{ select_by_map( condition: rbs:: Value ) ->Vec =>
180
- "trim end=' where ':
179
+ impl $table{
180
+ pub async fn select_by_map( executor: & dyn $crate:: executor:: Executor , condition: rbs:: Value ) -> std:: result:: Result <Vec <$table>, $crate:: rbdc:: Error >{
181
+ use rbatis:: crud_traits:: ValueOperatorSql ;
182
+ #[ $crate:: py_sql(
183
+ "`select * from ${table_name} `
184
+ trim end=' where ':
181
185
` where `
182
186
trim ' and ': for key,item in condition:
183
187
if !item.is_array():
@@ -187,8 +191,28 @@ macro_rules! impl_select {
187
191
trim ',': for _,item_array in item:
188
192
#{item_array},
189
193
`)`
190
- "
191
- } , $table_name) ;
194
+ " ) ]
195
+ async fn select_by_map(
196
+ executor: & dyn $crate:: executor:: Executor ,
197
+ table_name: String ,
198
+ condition: & rbs:: Value
199
+ ) -> std:: result:: Result <Vec <$table>, $crate:: rbdc:: Error >{
200
+ for ( _, v) in condition{
201
+ if v. is_array( ) && v. is_empty( ) {
202
+ return Ok ( vec![ ] ) ;
203
+ }
204
+ }
205
+ impled!( )
206
+ }
207
+ let mut table_name = $table_name. to_string( ) ;
208
+ if table_name. is_empty( ) {
209
+ #[ $crate:: snake_name( $table) ]
210
+ fn snake_name( ) { }
211
+ table_name = snake_name( ) ;
212
+ }
213
+ select_by_map( executor, table_name, & condition) . await
214
+ }
215
+ }
192
216
} ;
193
217
( $table: ty{ $fn_name: ident $( < $( $gkey: ident: $gtype: path $( , ) ?) * >) ?( $( $param_key: ident: $param_type: ty $( , ) ?) * ) => $sql: expr} $( , $table_name: expr) ?) =>{
194
218
$crate:: impl_select!( $table{ $fn_name$( <$( $gkey: $gtype, ) * >) ?( $( $param_key: $param_type, ) * ) ->Vec => $sql} $( , $table_name) ?) ;
@@ -204,9 +228,9 @@ macro_rules! impl_select {
204
228
let mut table_column ="*" . to_string( ) ;
205
229
let mut table_name =String :: new( ) ;
206
230
$( table_name = $table_name. to_string( ) ; ) ?
207
- #[ $crate:: snake_name( $table) ]
208
- fn snake_name( ) { }
209
231
if table_name. is_empty( ) {
232
+ #[ $crate:: snake_name( $table) ]
233
+ fn snake_name( ) { }
210
234
table_name = snake_name( ) ;
211
235
}
212
236
$fn_name( executor, & table_column, & table_name, $( $param_key, ) * ) . await
@@ -240,19 +264,52 @@ macro_rules! impl_update {
240
264
) ;
241
265
} ;
242
266
( $table: ty{ } , $table_name: expr) =>{
243
- $crate:: impl_update!( $table{ update_by_map( condition: rbs:: Value ) =>
244
- "trim end=' where ':
245
- ` where `
246
- trim ' and ': for key,item in condition:
267
+ impl $table{
268
+ pub async fn update_by_map(
269
+ executor: & dyn $crate:: executor:: Executor ,
270
+ table: & $table,
271
+ condition: rbs:: Value
272
+ ) -> std:: result:: Result <$crate:: rbdc:: db:: ExecResult , $crate:: rbdc:: Error >{
273
+ use rbatis:: crud_traits:: ValueOperatorSql ;
274
+ #[ $crate:: py_sql(
275
+ "`update ${table_name}`
276
+ set collection='table',skips='id':
277
+ trim end=' where ':
278
+ ` where `
279
+ trim ' and ': for key,item in condition:
247
280
if !item.is_array():
248
281
` and ${key.operator_sql()}#{item}`
249
282
if item.is_array():
250
283
` and ${key} in (`
251
284
trim ',': for _,item_array in item:
252
285
#{item_array},
253
286
`)`
254
- "
255
- } , $table_name) ;
287
+ "
288
+ ) ]
289
+ async fn update_by_map(
290
+ executor: & dyn $crate:: executor:: Executor ,
291
+ table_name: String ,
292
+ table: & rbs:: Value ,
293
+ condition: & rbs:: Value
294
+ ) -> std:: result:: Result <$crate:: rbdc:: db:: ExecResult , $crate:: rbdc:: Error >{
295
+ for ( _, v) in condition{
296
+ if v. is_array( ) && v. is_empty( ) {
297
+ return Ok ( $crate:: rbdc:: db:: ExecResult :: default ( ) ) ;
298
+ }
299
+ }
300
+ impled!( )
301
+ }
302
+ let mut table_name = $table_name. to_string( ) ;
303
+ if table_name. is_empty( ) {
304
+ #[ $crate:: snake_name( $table) ]
305
+ fn snake_name( ) { }
306
+ table_name = snake_name( ) ;
307
+ }
308
+ let table = rbs:: value!( table) ;
309
+ update_by_map( executor, table_name, & table, & condition) . await
310
+ }
311
+ }
312
+
256
313
} ;
257
314
( $table: ty{ $fn_name: ident( $( $param_key: ident: $param_type: ty$( , ) ?) * ) => $sql_where: expr} $( , $table_name: expr) ?) =>{
258
315
impl $table{
@@ -276,9 +333,9 @@ macro_rules! impl_update {
276
333
}
277
334
let mut table_name =String :: new( ) ;
278
335
$( table_name = $table_name. to_string( ) ; ) ?
279
- #[ $crate:: snake_name( $table) ]
280
- fn snake_name( ) { }
281
336
if table_name. is_empty( ) {
337
+ #[ $crate:: snake_name( $table) ]
338
+ fn snake_name( ) { }
282
339
table_name = snake_name( ) ;
283
340
}
284
341
let table = rbs:: value!( table) ;
@@ -313,19 +370,6 @@ macro_rules! impl_delete {
313
370
) ;
314
371
} ;
315
372
( $table: ty{ } , $table_name: expr) =>{
316
- // $crate::impl_delete!($table{ delete_by_map(condition:rbs::Value) =>
317
- // "trim end=' where ':
318
- // ` where `
319
- // trim ' and ': for key,item in condition:
320
- // if !item.is_array():
321
- // ` and ${key.operator_sql()}#{item}`
322
- // if item.is_array():
323
- // ` and ${key} in (`
324
- // trim ',': for _,item_array in item:
325
- // #{item_array},
326
- // `)`
327
- // "
328
- // },$table_name);
329
373
impl $table{
330
374
pub async fn delete_by_map( executor: & dyn $crate:: executor:: Executor , condition: rbs:: Value ) -> std:: result:: Result <$crate:: rbdc:: db:: ExecResult , $crate:: rbdc:: Error >{
331
375
use rbatis:: crud_traits:: ValueOperatorSql ;
@@ -341,21 +385,25 @@ macro_rules! impl_delete {
341
385
#{item_array},
342
386
`)`
343
387
" ) ]
344
- async fn delete_by_map_inner (
388
+ async fn delete_by_map (
345
389
executor: & dyn $crate:: executor:: Executor ,
346
390
table_name: String ,
347
- condition: rbs:: Value
391
+ condition: & rbs:: Value
348
392
) -> std:: result:: Result <$crate:: rbdc:: db:: ExecResult , $crate:: rbdc:: Error >{
393
+ for ( _, v) in condition{
394
+ if v. is_array( ) && v. is_empty( ) {
395
+ return Ok ( $crate:: rbdc:: db:: ExecResult :: default ( ) ) ;
396
+ }
397
+ }
349
398
impled!( )
350
399
}
351
-
352
400
let mut table_name = $table_name. to_string( ) ;
353
- # [ $crate :: snake_name ( $table ) ]
354
- fn snake_name( ) { }
355
- if table_name . is_empty ( ) {
356
- table_name = snake_name( ) ;
401
+ if table_name . is_empty ( ) {
402
+ # [ $crate :: snake_name( $table ) ]
403
+ fn snake_name ( ) { }
404
+ table_name = snake_name( ) ;
357
405
}
358
- delete_by_map_inner ( executor, table_name, condition) . await
406
+ delete_by_map ( executor, table_name, & condition) . await
359
407
}
360
408
}
361
409
} ;
@@ -379,9 +427,9 @@ macro_rules! impl_delete {
379
427
}
380
428
let mut table_name =String :: new( ) ;
381
429
$( table_name = $table_name. to_string( ) ; ) ?
382
- #[ $crate:: snake_name( $table) ]
383
- fn snake_name( ) { }
384
430
if table_name. is_empty( ) {
431
+ #[ $crate:: snake_name( $table) ]
432
+ fn snake_name( ) { }
385
433
table_name = snake_name( ) ;
386
434
}
387
435
$fn_name( executor, table_name, $( $param_key, ) * ) . await
@@ -421,11 +469,12 @@ macro_rules! impl_select_page {
421
469
) -> std:: result:: Result <$crate:: plugin:: Page :: <$table>, $crate:: rbdc:: Error >{
422
470
let mut table_column ="*" . to_string( ) ;
423
471
let mut table_name =String :: new( ) ;
472
+ let mut table_name =String :: new( ) ;
424
473
$( table_name = $table_name. to_string( ) ; ) ?
425
- #[ $crate:: snake_name( $table) ]
426
- fn snake_name( ) { }
427
474
if table_name. is_empty( ) {
428
- table_name = snake_name( ) ;
475
+ #[ $crate:: snake_name( $table) ]
476
+ fn snake_name( ) { }
477
+ table_name = snake_name( ) ;
429
478
}
430
479
$crate:: pysql_select_page!( $fn_name(
431
480
table_column: & str ,