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
// Copyright (c) 2021 akita contributors
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.
//! 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
//!
//! Put the desired version of the crate into the `dependencies` section of your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! akita = "0.4.0"
//! ```
//!
//!
//! ## Feature.
//!
//! * ```akita-mysql``` - to use mysql
//! * ```akita-sqlite``` - to use sqlite
//!
//!
//! ## Annotions.
//! * Table - to make Akita work with structs
//! * column - to make struct field with own database.
//! * name - work with column, make the table's field name. default struct' field name.
//! * exist - ignore struct's field with table. default true.
//!
//! ## Support Field Types.
//!
//! * ```Option<T>```
//! * ```u8, u32, u64```
//! * ```i32, i64```
//! * ```usize```
//! * ```f32, f64```
//! * ```bool```
//! * ```serde_json::Value```
//! * ```str, String```
//! * ```NaiveDate, NaiveDateTime```
//!
//! ## Example
//!
//! ```rust
//! # use akita::*;
//! # use chrono::{NaiveDateTime, NaiveDate};
//! # use std::time::Duration;
//! # use once_cell::sync::Lazy;
//! /// Annotion Support: AkitaTable、table_id、field (name, exist)
//! #[derive(AkitaTable, Clone, Default)]
//! #[table(name = "t_system_user")]
//! pub struct User {
//! #[table_id(name = "id")]
//! pub pk: i64,
//! pub id: String,
//! pub headline: Option<NaiveDateTime>,
//! /// 状态
//! pub status: u8,
//! /// 用户等级 0.普通会员 1.VIP会员
//! pub level: u8,
//! /// 生日
//! pub birthday: Option<NaiveDate>,
//! /// 性别
//! pub gender: u8,
//! #[field(exist = "false")]
//! pub is_org: bool,
//! #[field(name = "token")]
//! pub url_token: String,
//! }
//!
//!
//! fn main() {
//!
//! let cfg = AkitaConfig::new(String::from("mysql://root:password@localhost:3306/akita"))
//! .set_connection_timeout(Duration::from_secs(6))
//! .set_log_level(LogLevel::Info).set_max_size(6);
//! let akita = Akita::new(cfg).expect("must be ok");
//! // The Wrapper to build query condition
//! let wrapper = Wrapper::new()
//! .eq("username", "ussd") // username = 'ussd'
//! .gt("age", 1) //! age > 1
//! .lt("age", 10) // age < 10
//! .inside("user_type", vec!["admin", "super"]) // user_type in ('admin', 'super')
//! .and(|wrapper| { // or
//! wrapper.like("username", &name)
//! .or_direct().like("username", &name)
//! });
//! // CRUD with Akita
//! let insert_id: Option<i32> = akita.save(&User::default()).unwrap();
//! let _ = akita.save_batch(&[&User::default()]).unwrap();
//! // Update with wrapper
//! let res = akita.update(&User::default(), Wrapper::new().eq("name", "Jack")).unwrap();
//! // Update with primary id
//! let res = akita.update_by_id(&User::default());
//! // Query return List
//! let list: Vec<User> = akita.list(Wrapper::new().eq("name", "Jack")).unwrap();
//! // Query return Page
//! let pageNo = 1;
//! let pageSize = 10;
//! let page: IPage<User> = akita.page(pageNo, pageSize, Wrapper::new().eq("name", "Jack")).unwrap();
//! // Remove with wrapper
//! let res = akita.remove::<User>(Wrapper::new().eq("name", "Jack")).unwrap();
//! // Remove with primary id
//! let res = akita.remove_by_id::<User,_>(0).unwrap();
//! // Get the record count
//! let count = akita.count::<User>(Wrapper::new().eq("name", "Jack")).unwrap();
//! // Query with original sql
//! let user: User = akita.exec_first("select * from t_system_user where name = ? and id = ?", ("Jack", 1)).unwrap();
//! // Or
//! let user: User = akita.exec_first("select * from t_system_user where name = :name and id = :id", params! {
//! "name" => "Jack",
//! "id" => 1
//! }).unwrap();
//! let res = akita.exec_drop("select now()", ()).unwrap();
//!
//! // Transaction
//! akita.start_transaction().and_then(|mut transaction| {
//! let list: Vec<User> = transaction.list(Wrapper::new().eq("name", "Jack"))?;
//! let insert_id: Option<i32> = transaction.save(&User::default())?;
//! transaction.commit()
//! }).unwrap();
//!
//! // CRUD with Entity
//! let model = User::default();
//! // insert
//! let insert_id = model.insert::<Option<i32>, _>(&akita).unwrap();
//! // update
//! let res = model.update_by_id::<_>(&akita).unwrap();
//! // delete
//! let res = model.delete_by_id::<i32,_>(&akita, 1).unwrap();
//! // list
//! let list = User::list::<_>(Wrapper::new().eq("name", "Jack"), &akita).unwrap();
//! // page
//! let page = User::page::<_>(pageNo, pageSize, Wrapper::new().eq("name", "Jack"), &akita).unwrap();
//!
//! // Fast with sql
//! pub static AK: Lazy<Akita> = Lazy::new(|| {
//! let mut cfg = AkitaConfig::new("xxxx".to_string()).set_max_size(5).set_connection_timeout(Duration::from_secs(5)).set_log_level(LogLevel::Info);
//! Akita::new(cfg).unwrap()
//! });
//!
//! #[sql(AK,"select * from user where id = ?")]
//! fn select_example(id: &str) -> Vec<User> { todo!() }
//!
//! // or:
//! #[sql(AK,"select * from user where mch_no = ?")]
//! fn select_example2(ak: &AKita, id: &str) -> Vec<User> { todo!() }
//! }
//! ```
//! ## API Documentation
//! ## Wrapper
//! ```ignore
//!
//! let mut wrapper = Wrapper::new().like(true, "column1", "ffff")
//! .eq(true, "column2", 12)
//! .eq(true, "column3", "3333")
//! .inside(true, "column4", vec![1,44,3])
//! .not_between(true, "column5", 2, 8)
//! .set(true, "column1", 4);
//!
//! ```
//! Update At 2021.12.08 10:21
//! By Mr.Pan
//!
//!
//!
mod wrapper;
mod segment;
mod errors;
mod mapper;
mod pool;
mod database;
mod platform;
#[cfg(feature = "akita-auth")]
mod auth;
mod manager;
#[allow(unused)]
#[cfg(feature = "akita-fuse")]
mod fuse;
mod akita;
#[doc(inline)]
pub use wrapper::Wrapper;
#[doc(inline)]
pub use database::Platform;
#[doc(inline)]
pub use mapper::{BaseMapper, IPage, AkitaMapper};
#[doc(inline)]
pub use segment::{Segment, AkitaKeyword, ISegment};
#[doc(inline)]
pub use errors::AkitaError;
#[doc(inline)]
pub use pool::{AkitaConfig, LogLevel, Pool};
#[cfg(feature = "akita-auth")]
pub use auth::*;
#[cfg(feature = "akita-fuse")]
pub use fuse::*;
pub use akita::*;
#[doc(inline)]
pub use manager::{AkitaEntityManager};
#[doc(inline)]
pub use chrono::{Local, NaiveDate, NaiveDateTime};
// Re-export #[derive(AkitaTable)].
//
// The reason re-exporting is not enabled by default is that disabling it would
// be annoying for crates that provide handwritten impls or data formats. They
// would need to disable default features and then explicitly re-enable std.
#[allow(unused_imports)]
#[macro_use]
extern crate akita_derive;
#[doc(hidden)]
pub use akita_derive::*;
pub use akita_core as core;
pub use akita_core::*;
pub use crate::core::{FieldName, FieldType, GetFields, GetTableName, Table, ToValue, FromValue};
pub use akita_core::*;
#[cfg(feature = "akita-logging")]
extern crate log;
#[cfg(feature = "akita-tracing")]
extern crate tracing;