-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathmacro_proc_htmlsql_struct.rs
More file actions
81 lines (74 loc) · 2.36 KB
/
macro_proc_htmlsql_struct.rs
File metadata and controls
81 lines (74 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use rbatis::dark_std::defer;
use rbatis::rbdc::datetime::DateTime;
use rbatis::{Error, RBatis};
#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct Activity {
pub id: Option<String>,
pub name: Option<String>,
pub pc_link: Option<String>,
pub h5_link: Option<String>,
pub pc_banner_img: Option<String>,
pub h5_banner_img: Option<String>,
pub sort: Option<String>,
pub status: Option<i32>,
pub remark: Option<String>,
pub create_time: Option<DateTime>,
pub version: Option<i64>,
pub delete_flag: Option<i32>,
}
/// All methods read SQL from example/example.html
#[rbatis::html_sql("example/example.html")]
impl Activity {
/// Maps to <select id="select_by_condition"> in HTML
pub async fn select_by_condition(
rb: &dyn rbatis::Executor,
name: &str,
dt: &DateTime,
) -> rbatis::Result<Vec<Activity>> {
impled!()
}
/// Maps to <select id="select_page_data"> in HTML
pub async fn select_page_data(
rb: &dyn rbatis::Executor,
page_req: &rbatis::PageRequest,
name: &str,
dt: &DateTime,
) -> rbatis::Result<rbatis::Page<Activity>> {
impled!()
}
/// Maps to <update id="update_by_id"> in HTML
pub async fn update_by_id(
rb: &dyn rbatis::Executor,
arg: &Activity,
) -> rbatis::Result<rbatis::rbdc::ExecResult> {
impled!()
}
/// Paginated query - automatically detected by return type Page<Activity>
/// Maps to <select id="select_by_page"> in HTML
/// The macro automatically generates pagination logic using PageIntercept
pub async fn select_by_page(
rb: &dyn rbatis::Executor,
page_req: &rbatis::PageRequest,
name: &str,
dt: Option<DateTime>,
) -> rbatis::Result<rbatis::Page<Activity>> {
impled!()
}
}
#[tokio::main]
pub async fn main() -> Result<(), Error> {
_ = fast_log::init(
fast_log::Config::new()
.console()
.level(log::LevelFilter::Debug),
);
defer!(|| {
log::logger().flush();
});
let rb = RBatis::new();
rb.init(rbdc_sqlite::SqliteDriver {}, "sqlite://target/sqlite.db")?;
// Use impl block Mapper
let results = Activity::select_by_page(&rb, &rbatis::PageRequest::new(1, 10), "", None).await?;
println!("Query by condition: {}", rbs::value!(results));
Ok(())
}