Crate akita[−][src]
Expand description
This create offers:
- MySql database’s helper in pure rust;
- A mini orm framework (Just MySQL)。
Features:
- Other Database support, i.e. support SQLite, Oracle, MSSQL…;
- support of original SQL;
- support of named parameters for custom condition;
Installation
Put the desired version of the crate into the dependencies
section of your Cargo.toml
:
[dependencies]
akita = "*"
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
use akita::*;
use akita::prelude::*;
/// Annotion Support: Table、table_id、field (name, exist)
#[derive(Debug, FromAkita, ToAkita, Table, Clone)]
#[table(name="t_system_user")]
struct SystemUser {
#[field = "name"]
id: Option<i32>,
#[table_id]
username: String,
#[field(name="ages", exist = "false")]
age: i32,
}
fn main() {
let db_url = String::from("mysql://root:password@localhost:3306/akita");
let mut pool = Pool::new(AkitaConfig{ max_size: None, url: db_url, log_level: None }).unwrap();
let mut em = pool.entity_manager().expect("must be ok");
let mut wrap = UpdateWrapper::new();
wrap.eq(true, "username", "'ussd'");
match em.count::<SystemUser, UpdateWrapper>(&mut wrap) {
Ok(res) => {
println!("success count data!");
}
Err(err) => {
println!("error:{:?}",err);
}
}
}
API Documentation
Wrapper
ⓘ
let mut wrapper = UpdateWrapper::new();
wrapper.like(true, "column1", "ffff");
wrapper.eq(true, "column2", 12);
wrapper.eq(true, "column3", "3333");
wrapper.in_(true, "column4", vec![1,44,3]);
wrapper.not_between(true, "column5", 2, 8);
wrapper.set(true, "column1", 4);
match wrapper.get_target_sql("t_user") {
Ok(sql) => {println!("ok:{}", sql);}
Err(err) => {println!("err:{}", err);}
}
Update At 2021.08.04 10:21 By Mr.Pan
Re-exports
pub use crate as akita;
Modules
Macros
This macro is a convenient way to pass named parameters to a statement.
Structs
an interface executing sql statement and getting the results as generic Akita values without any further conversion.
An iterator over Row
s.
use this to store data retrieved from the database
This is also slimmer than Vec
Enums
Traits
A trait to allow passing of parameters ergonomically in em.execute_sql_with_return