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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! Procedural macro to automatically generate SQL statements traits `TableStatement`, `SelectStatement`, `InsertStatement`, `DeleteStatement` for the
//! provided struct as well as conversion to SQL parameters and from SQL rows.
//!
//! # How to use
//!
//! You write:
//! ```rust
//! # use derive_sql::*;
//! #[derive(derive_sql::DeriveSqlStatement)]
//! pub struct Person {
//! name: String,
//! age: u32,
//! }
//! ```
//!
//! And you can use:
//! ```rust
//! # use derive_sql::*;
//! # #[derive(DeriveSqlStatement)]
//! # pub struct Person {
//! # name: String,
//! # age: u32,
//! # }
//! use derive_sql::structs::*;
//!
//! fn handle<Con, Row>(s: &mut Con)
//! where Con: traits::Connection<Row>,
//! Row: traits::Row,
//! {
//! use derive_sql::traits::{Table, SelectV2, Insert, Delete, Update};
//! let db = SqlPerson::default();
//!
//! // initialise
//! db.create(s).unwrap();
//!
//! // Insert entries
//! db.insert(s, &Person {name: "Abi".to_string(), age: 31 }).unwrap();
//! db.insert(s, &Person {name: "Bert".to_string(), age: 32 }).unwrap();
//! db.insert(s, &Person {name: "Charlie".to_string(), age: 33 }).unwrap();
//!
//! // Query
//! let persons: Vec<Person> = db.select_with_filter(s, &Field::from("age").eq(32)).unwrap();
//! assert!(persons[0].name.eq("Bert"));
//!
//! // Update
//! db.update_with_filter(s, &Field::from("name").eq("Abi"), &Person { name: "Abi".to_string(), age: 32 }).unwrap();
//!
//! // Delete
//! db.delete_with_filter(s, &Field::from("name").eq("Abi")).unwrap();
//!
//! // Clear the table
//! db.drop(s).unwrap();
//! }
//!
//! let pool = mysql::Pool::new("mysql://test@localhost/simpledb").unwrap();
//! let mut connection = pool.get_conn().unwrap();
//! handle(&mut connection);
//! ```
//!
//! # Container attributes:
//! - `#[derive_sqlite(ident = ...)]` overwrite the name of the wrapper from `Sql{class}`;
//! - `#[derive_sqlite(table_name = "...")]` specify the name of the table (default to the container name in lower case);
//! - `#[derive_sqlite(read_only = true/false)]` specify whether to implement read/write (ie table, select, insert, update, delete, to params conversion and from row conversion)
//! or read only statements (ie select and from row conversion)
//!
//! # Field attributes:
//! - `#[derive_sqlite(is_primary_key = true)]` nominate that one of the field is a primary key. Only one primary key can be specified.
//! primary key fields are unique in the table. Primary key can NOT be a String - the following will not compile:
//!
//! ```compile_fail
//! # use derive_sql::*;
//! # use derive_sql_mysql::DeriveMysql;
//! #[derive(DeriveMysql)]
//! pub struct Person {
//! #[derive_sqlite(is_primary_key = true)]
//! name: String,
//! age: u32,
//! }
//! ```
//!
use ;