一个基于sqlx的极简orm,本项目将sql代码以derive属性方式和结构体进行关联,并自动生成相关CRUD相关API,可根据需要实现任意复杂度的数据获取。
本项目开发主要原因:
因此,是否可以将数据查询的sql和rust结合,由程序员自行控制sql的表现,这样在rust的高性能助力下,我们可以写成性能超级赞的数据库应用。
``` use sqlx::mysql::MySqlPoolOptions; use sqlx::Row; use tinyormmacro_derive::{TinyOrm, TinyOrmQuery};
use super::*;
pub struct UserType {
/// 类型编号
pub id: Option
pub struct TestUser {
/// 类型编号
pub id: Option
impl TestUser {
/// 完整创建器
///
/// # 参数说明
///
/// * id 编号
/// * name 姓名
/// * mobilephone 手机
/// * password 密码
/// * usertype 用户类型
/// * org 对应机构
pub fn new(
id: u32,
name: &str,
mobilephone: &str,
password: &str,
usertype: UserType,
) -> Self {
Self {
id: Some(id),
name: name.into(),
mobilephone: mobilephone.into(),
password: password.into(),
usertype,
}
}
}
/// 实现数据获取接口
impl TinyOrmData for TestUser {
/// 将sql返回数据映射为TestUser
fn ormrowmap(row: TinyOrmSqlRow) -> Self {
TestUser::new(
row.get::