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

Appearance settings

Commit d0da0cf

Browse filesBrowse files
committed
select in column fix
1 parent 4f60984 commit d0da0cf
Copy full SHA for d0da0cf

File tree

Expand file treeCollapse file tree

3 files changed

+16
-36
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-36
lines changed

‎Cargo.toml

Copy file name to clipboardExpand all lines: Cargo.toml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ members = [
88

99
[package]
1010
name = "rbatis"
11-
version = "4.5.48"
11+
version = "4.5.49"
1212
description = "The Rust SQL Toolkit and ORM Library. An async, pure Rust SQL crate featuring compile-time Dynamic SQL"
1313
readme = "Readme.md"
1414
authors = ["ce <zhuxiujia@qq.com>"]

‎example/src/crud_select.rs

Copy file name to clipboardExpand all lines: example/src/crud_select.rs
+7-31Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use log::LevelFilter;
22
use rbatis::dark_std::defer;
33
use rbatis::rbdc::datetime::DateTime;
44
use rbatis::table_sync::SqliteTableMapper;
5-
use rbatis::RBatis;
5+
use rbatis::{crud, RBatis};
66
use serde_json::json;
77
use rbatis::impl_select;
8+
use rbatis::rbdc::db::ExecResult;
89

910
/// table
1011
#[derive(serde::Serialize, serde::Deserialize)]
@@ -22,7 +23,7 @@ pub struct Activity {
2223
pub version: Option<i64>,
2324
pub delete_flag: Option<i32>,
2425
}
25-
26+
crud!(Activity{});
2627
impl_select!(Activity{select_id_name(id:&str,name:&str) => "`where id = #{id} and name = #{name}`"});
2728

2829
#[tokio::main]
@@ -38,38 +39,13 @@ pub async fn main() {
3839

3940
let rb = RBatis::new();
4041
// ------------choose database driver------------
41-
// rb.init(rbdc_mysql::driver::MysqlDriver {}, "mysql://root:123456@localhost:3306/test").unwrap();
42+
rb.init(rbdc_mysql::driver::MysqlDriver {}, "mysql://root:123456@localhost:3306/test").unwrap();
4243
// rb.init(rbdc_pg::driver::PgDriver {}, "postgres://postgres:123456@localhost:5432/postgres").unwrap();
4344
// rb.init(rbdc_mssql::driver::MssqlDriver {}, "mssql://jdbc:sqlserver://localhost:1433;User=SA;Password={TestPass!123456};Database=master;").unwrap();
44-
rb.init(rbdc_sqlite::driver::SqliteDriver {}, "sqlite://target/sqlite.db").unwrap();
45+
//rb.init(rbdc_sqlite::driver::SqliteDriver {}, "sqlite://target/sqlite.db").unwrap();
4546
// table sync done
46-
sync_table(&rb).await;
47-
48-
let data = Activity::select_id_name(&rb, "1", "1").await;
47+
let data = Activity::select_in_column::<i32>(&rb, "id", &[]).await;
4948
println!("select_id_name = {}", json!(data));
5049
}
5150

52-
async fn sync_table(rb: &RBatis) {
53-
fast_log::logger().set_level(LevelFilter::Off);
54-
_ = RBatis::sync(
55-
&rb.acquire().await.unwrap(),
56-
&SqliteTableMapper {},
57-
&Activity {
58-
id: Some(String::new()),
59-
name: Some(String::new()),
60-
pc_link: Some(String::new()),
61-
h5_link: Some(String::new()),
62-
pc_banner_img: Some(String::new()),
63-
h5_banner_img: Some(String::new()),
64-
sort: Some(String::new()),
65-
status: Some(0),
66-
remark: Some(String::new()),
67-
create_time: Some(DateTime::now()),
68-
version: Some(0),
69-
delete_flag: Some(0),
70-
},
71-
"activity",
72-
)
73-
.await;
74-
fast_log::logger().set_level(LevelFilter::Debug);
75-
}
51+

‎src/crud.rs

Copy file name to clipboardExpand all lines: src/crud.rs
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,20 @@ macro_rules! impl_select {
214214
"` where ${column} in (`
215215
trim ',': for _,item in column_values:
216216
#{item},
217-
`)`"},$table_name);
217+
`)`"},$table_name => { if column_values.is_empty() { return Ok(vec![]); }} );
218218
};
219219
($table:ty{$fn_name:ident $(< $($gkey:ident:$gtype:path $(,)?)* >)? ($($param_key:ident:$param_type:ty $(,)?)*) => $sql:expr}$(,$table_name:expr)?) => {
220220
$crate::impl_select!($table{$fn_name$(<$($gkey:$gtype,)*>)?($($param_key:$param_type,)*) ->Vec => $sql}$(,$table_name)?);
221221
};
222-
($table:ty{$fn_name:ident $(< $($gkey:ident:$gtype:path $(,)?)* >)? ($($param_key:ident:$param_type:ty $(,)?)*) -> $container:tt => $sql:expr}$(,$table_name:expr)?) => {
222+
($table:ty{$fn_name:ident $(< $($gkey:ident:$gtype:path $(,)?)* >)? ($($param_key:ident:$param_type:ty $(,)?)*) -> $container:tt => $sql:expr}$(,$table_name:expr)? $( => $cond:expr)? ) => {
223223
impl $table{
224224
pub async fn $fn_name $(<$($gkey:$gtype,)*>)? (executor: &dyn $crate::executor::Executor,$($param_key:$param_type,)*) -> std::result::Result<$container<$table>,$crate::rbdc::Error>
225225
{
226226
#[$crate::py_sql("`select ${table_column} from ${table_name} `",$sql)]
227227
async fn $fn_name$(<$($gkey: $gtype,)*>)?(executor: &dyn $crate::executor::Executor,table_column:&str,table_name:&str,$($param_key:$param_type,)*) -> std::result::Result<$container<$table>,$crate::rbdc::Error> {impled!()}
228+
229+
$($cond)?
230+
228231
let mut table_column = "*".to_string();
229232
let mut table_name = String::new();
230233
$(table_name = $table_name.to_string();)?
@@ -398,7 +401,7 @@ macro_rules! impl_delete {
398401
"`where ${column} in (`
399402
trim ',': for _,item in column_values:
400403
#{item},
401-
`)`"},$table_name);
404+
`)`"},$table_name => { if column_values.is_empty() { return Ok($crate::rbdc::db::ExecResult::default()); }} );
402405

403406
impl $table {
404407
pub async fn delete_by_column_batch<V:serde::Serialize>(
@@ -419,7 +422,7 @@ macro_rules! impl_delete {
419422
}
420423
}
421424
};
422-
($table:ty{$fn_name:ident $(< $($gkey:ident:$gtype:path $(,)?)* >)? ($($param_key:ident:$param_type:ty$(,)?)*) => $sql_where:expr}$(,$table_name:expr)?) => {
425+
($table:ty{$fn_name:ident $(< $($gkey:ident:$gtype:path $(,)?)* >)? ($($param_key:ident:$param_type:ty$(,)?)*) => $sql_where:expr}$(,$table_name:expr)? $( => $cond:expr)?) => {
423426
impl $table {
424427
pub async fn $fn_name$(<$($gkey:$gtype,)*>)?(
425428
executor: &dyn $crate::executor::Executor,
@@ -436,6 +439,7 @@ macro_rules! impl_delete {
436439
) -> std::result::Result<$crate::rbdc::db::ExecResult, $crate::rbdc::Error> {
437440
impled!()
438441
}
442+
$($cond)?
439443
let mut table_name = String::new();
440444
$(table_name = $table_name.to_string();)?
441445
#[$crate::snake_name($table)]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.