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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
*
* *
* * Copyright (c) 2018-2025, SnackCloud All rights reserved.
* *
* * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions are met:
* *
* * Redistributions of source code must retain the above copyright notice,
* * this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* * notice, this list of conditions and the following disclaimer in the
* * documentation and/or other materials provided with the distribution.
* * Neither the name of the www.snackcloud.cn developer nor the names of its
* * contributors may be used to endorse or promote products derived from
* * this software without specific prior written permission.
* * Author: SnackCloud
* *
*
*/
//! This create offers:
//!
//! * MySql/SQLite database's helper in pure rust;
//! * A mini orm framework (Just MySQL/SQLite)。
//!
//! Features:
//!
//! * Other Database support, i.e. support Oracle, MSSQL...;
//! * support of named parameters for custom condition;
//!
//! ## Installation
//!
//!
//! Add this to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! akita = { version = "0.6", features = ["mysql-sync"] }
//! chrono = "0.4"
//! ```
//!
//! For SQLite support:
//! ```toml
//! [dependencies]
//! akita = { version = "0.4", features = ["sqlite-sync"] }
//! ```
//!
//! ## 🚀 Quick Start
//! ### 1. Define Your Entity
//!
//! ```rust
//! use akita::prelude::*;
//! use chrono::{NaiveDate, NaiveDateTime};
//! use serde_json::Value;
//!
//! #[derive(Entity, Clone, Default, Debug)]
//! #[table(name = "users")]
//! pub struct User {
//! #[id(name = "id")]
//! pub id: i64,
//!
//! #[field(name = "user_name")]
//! pub username: String,
//!
//! pub email: String,
//!
//! pub age: Option<u8>,
//!
//! #[field(name = "is_active")]
//! pub active: bool,
//!
//! pub level: u8,
//!
//! pub metadata: Option<Value>,
//!
//! pub birthday: Option<NaiveDate>,
//!
//! pub created_at: Option<NaiveDateTime>,
//!
//! #[field(exist = "false")]
//! pub full_name: String,
//! }
//! ```
//!
//! ### 2. Initialize Akita
//!
//! ```rust
//! use akita::prelude::*;
//! use std::time::Duration;
//!
//! async fn main() -> Result<(), AkitaError> {
//! // Configuration
//! let cfg = AkitaConfig::new().url("mysql://!root:password@localhost:3306/mydb")
//! .max_size(10) //! Connection pool size
//! .connection_timeout(Duration::from_secs(5));
//!
//! // Create Akita instance
//! let akita = Akita::new(cfg)?;
//!
//! Ok(())
//! }
//! ```
//!
//! ### 3. Basic Operations
//!
//! ```rust
//! // Create
//! let user = User {
//! username: "john_doe".to_string(),
//! email: "john@example.com".to_string(),
//! active: true,
//! level: 1,
//! ..Default::default()
//! };
//!
//! let user_id: Option<i64> = akita.save(&user)?;
//!
//! // Read
//! let user: Option<User> = akita.select_by_id(user_id.unwrap())?;
//!
//! // Update
//! let mut user = user.unwrap();
//! user.level = 2;
//! akita.update_by_id(&user)?;
//!
//! // Delete
//! akita.remove_by_id::<User, _>(user_id.unwrap())?;
//! ```
//!
//! ## 📚 Detailed Usage
//! ### Query Builder
//!
//! Akita provides a powerful, type-safe query builder:
//! ```rust
//! use akita::prelude::*;
//!
//! let wrapper = Wrapper::new()
//! // Select specific columns
//! .select(vec!["id", "username", "email"])
//!
//! // Conditions
//! .eq("status", 1)
//! .ne("deleted", true)
//! .gt("age", 18)
//! .ge("score", 60)
//! .lt("age", 65)
//! .le("level", 10)
//!
//! // String operations
//! .like("username", "%john%")
//! .not_like("email", "%test%")
//!
//! // List operations
//! .r#in("role", vec!["admin", "user"])
//! .not_in("status", vec![0, 9])
//!
//! // Null checks
//! .is_null("deleted_at")
//! .is_not_null("created_at")
//!
//! // Between
//! .between("age", 18, 65)
//! .not_between("score", 0, 60)
//!
//! // Logical operations
//! .and(|w| {
//! w.eq("status", 1).or_direct().eq("status", 2)
//! })
//! .or(|w| {
//! w.like("username", "%admin%").like("email", "%admin%")
//! })
//!
//! // Ordering
//! .order_by_asc(vec!["created_at"])
//! .order_by_desc(vec!["id", "level"])
//!
//! // Grouping
//! .group_by(vec!["department", "level"])
//!
//! // Having clause
//! .having("COUNT(*)", SqlOperator::Gt, 1)
//!
//! // Pagination
//! .limit(10)
//! .offset(20);
//! ```
//!
//! ### Complex Queries
//! ```rust
//! // Join queries
//! let users: Vec<User> = akita.list(
//! Wrapper::new()
//! .eq("u.status", 1)
//! .inner_join("departments d","u.department_id = d.id")
//! .select(vec!["u.*", "d.name as department_name"])
//! )?;
//!
//! // Subqueries
//! let active_users: Vec<User> = akita.list(
//! Wrapper::new()
//! .r#in("id", |w| {
//! w.select(vec!["user_id"])
//! .from("user_logs")
//! .eq("action", "login")
//! .gt("created_at", "2023-01-01")
//! })
//! )?;
//! ```
//!
//! ### Raw SQL Queries
//! ```rust
//! // Parameterized queries
//! let users: Vec<User> = akita.exec_raw(
//! "SELECT * FROM users WHERE status = ? AND level > ?",
//! (1, 0)
//! )?;
//!
//! // Named parameters
//! let user: Option<User> = akita.exec_first(
//! "SELECT * FROM users WHERE username = :name AND email = :email",
//! params! {
//! "name" => "john",
//! "email" => "john@example.com"
//! }
//! )?;
//!
//! // Executing DDL
//! akita.exec_drop(
//! "CREATE TABLE IF NOT EXISTS users (
//! id BIGINT PRIMARY KEY AUTO_INCREMENT,
//! username VARCHAR(50) NOT NULL,
//! email VARCHAR(100) NOT NULL
//! )",
//! ()
//! )?;
//! ```
//! Update At 2025.12.13 12:13
//! By Mr.Pan
//!
//!
//!
// Common core module