Akita - Mini orm for rust
This create offers: * MySql database's helper in pure rust; * SQLite database's helper in pure rust; * A mini orm framework (With MySQL/SQLite)。
Features:
You may be looking for:
Click to show Cargo.toml.
Run this code in the playground.
```toml [dependencies]
akita = { version = "0.3.0", features = ["akita-mysql"] }
```
```rust use akita::; use akita::prelude::;
/// Annotion Support: AkitaTable、table_id、field (name, exist, fill(function, mode))
pub struct User {
#[tableid(name = "id")]
pub pk: i64,
pub id: String,
pub headline: Option
static area: &str = "china";
fn isorgbuild() -> bool { area.eq("china") }
fn token_build() -> String { // generate the token todo!() }
### CRUD with EntityManager
rust
fn main() {
let dburl = String::from("mysql://root:password@localhost:3306/akita");
let cfg = AkitaConfig::new(dburl).setconnectiontimeout(Duration::fromsecs(6))
.setloglevel(LogLevel::Debug).setmaxsize(6);
let mut pool = Pool::new(cfg).expect("must be ok");
let mut entitymanager = pool.entitymanager().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("usertype", vec!["admin", "super"]); // usertype in ('admin', 'super')
// CRUD with EntityManager
let insertid: Option
fn main() { let dburl = String::from("mysql://root:password@localhost:3306/akita"); let cfg = AkitaConfig::new(dburl).setconnectiontimeout(Duration::fromsecs(6)) .setloglevel(LogLevel::Debug).setmaxsize(6); let mut pool = Pool::new(cfg).expect("must be ok"); let mut entitymanager = pool.entitymanager().expect("must be ok"); // CRUD with Entity let model = User::default(); // insert let insertid = model.insert::
fn main() {
let dburl = String::from("mysql://root:password@localhost:3306/akita");
let cfg = AkitaConfig::new(dburl).setconnectiontimeout(Duration::fromsecs(6))
.setloglevel(LogLevel::Debug).setmaxsize(6);
let mut pool = Pool::new(cfg).expect("must be ok");
let mut entitymanager = pool.entitymanager().expect("must be ok");
// Fast with Akita
let list: Vec
let page: IPage<User> = Akita::new().conn(pool.database().unwrap())
.table("t_system_user")
.wrapper(Wrapper::new().eq("name", "Jack"))
.page::<User>(1, 10).unwrap();
// ...
// Transaction
entity_manager.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();
} ```
### 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);
```
akita-mysql
- to use mysqlakita-sqlite
- to use sqliteakita-auth
- to use some auth mehodAkitaTable
- to make Akita work with structsFromValue
- from value with akitaToValue
- to value with akitatable_id
- to make Table Identfield
- 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.Option<T>
u8, u32, u64
i32, i64
usize
bool
f32, f64
str, String
serde_json::Value
NaiveDate, NaiveDateTime
To setup the development envrionment run cargo run
.
MrPan <1049058427@qq.com>
Akita is a personal project. At the beginning, I just like Akita dog because of my hobbies. I hope this project will grow more and more lovely. Many practical database functions will be added in the future. I hope you can actively help this project grow and put forward suggestions. I believe the future will be better and better.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Akita by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.