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
//! Do dynamic-sql query through proc-macro
//!
//! It bases on [**sqlx**] crate (default feature), you can switch them by setting the features.
//! It uses [**Ramhorns-ext**] the high performance template engine implementation of [**Mustache**]
//!
//! ## Example (Sqlx)
//!
//! ### main.rs
//! ```ignore
//! //...
//!
//! # #[tokio::main]
//! async fn main() {
//! let conn = connect_postgres_db().await;
//!
//! // fetch all
//! let dto = UserDto{ id: None, name: None, age: Some(15) };
//! let rst = fetch_all!(|&dto, &conn| -> User {
//! r#"SELECT * FROM test_user
//! WHERE 1 = 1
//! {{#name}}AND name = :name{{/name}}
//! {{#age}}AND age > :age{{/age}}
//! ORDER BY id"#
//! }).unwrap();
//! assert_eq!(
//! vec![
//! User { id: 2, name: Some("zhanglan".to_owned()), age: Some(21) },
//! User { id: 3, name: Some("zhangsan".to_owned()), age: Some(35) }
//! ],
//! rst
//! );
//!
//! let rst = fetch_one!(...).unwrap();
//!
//! let rst = fetch_scalar!(...).unwrap();
//!
//! let affected_rows_num = execute!(...).unwrap();
//!
//! let insert_id = insert!(...).unwrap();
//!
//! sql!('sql_fragment_1', "select * from table1");
//! let rst = fetch_one!(|...| sql_fragment_1 + "where age > 10").unwrap();
//!
//! let mut page_dto = ...;
//! let pagination = page!(|&mut page_dto, &conn| -> User).unwrap();
//! }
//! ```
//!
//! ## Example (sqlx)
//! Full example please see: [Dysql sqlx example](https://github.com/evanzp0/dysql-project/tests)
pub use *;
pub use *;
pub use *;