Crate akita[][src]

Expand description

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:

[dependencies]
akita = "*"

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

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.09.05 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 Rows.

use this to store data retrieved from the database This is also slimmer than Vec when serialized

Enums

AkitaKeyword is mainly used to distinguish whether it is the type of database function or other keywords If you need to use some system functions or keywords, you can distinguish them from ordinary strings

Segment are generally not used directly unless you are using the more low level functionality in the library. For the most part this is hidden with the help of the ToSegment trait.

Traits

A trait to allow passing of parameters ergonomically in em.execute_sql_with_return

Functions