Comments (4)
我看到Domain层的逻辑
#[derive(Serialize, Deserialize, Clone, Debug)] pub struct SysUser { pub id: Option<String>, pub account: Option<String>, pub password: Option<String>, pub name: Option<String>, pub del: Option<i32>, pub create_time: Option<NaiveDateTime>, } impl CRUDEnable for SysUser { type IdType = String; }
可以用宏来简洁一下
主意是很不错。
但是:
1 如果使用宏的话,我们需要自定义表名称 怎么办。目前CRUDEnable 重写table_name()方法可以做到。还有其他的方法如table_fields可以重写自定义表字段(忽略某些用不得的字段)
2 宏要自动识别Id类型 抛给 CRUDEnable trait。假如SysUser没有id这个field,用 account 作为id类型,那么宏如何识别id的类型?
3 是用过程宏还是申明宏?申明宏是否支持上面说的内容。
如果这几个问题能解决,那么可以使用宏。如果有解决方法,欢迎提交代码~~
补充:
不过,在你自己的项目里 可以写一个宏 简化。
例如 ,
macro_rules! impl_crud_enable {
($x:ident) => {
impl rbatis::crud::CRUDEnable for $x {
type IdType = String;
}
};
}
impl_crud_enable!(SysUser);//不过,,看起来并没有省多少代码量
from rbatis.
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SysUser {
pub id: Option<String>,
pub account: Option<String>,
pub password: Option<String>,
pub name: Option<String>,
pub del: Option<i32>,
pub create_time: Option<NaiveDateTime>,
}
impl CRUDEnable for SysUser {
type IdType = String;
}
对于上面的简化
我提供下面思路,我觉得可行:
1、简化版本,无需自定义
#[derive(Serialize, Deserialize, Clone, Debug, CRUDEnable)]
pub struct SysUser {
pub id: Option<String>,
pub account: Option<String>,
pub password: Option<String>,
pub name: Option<String>,
pub del: Option<i32>,
pub create_time: Option<NaiveDateTime>,
}
2、需自定义
#[derive(Serialize, Deserialize, Clone, Debug, CRUDEnable)]
#[rbatis(table="t_user", id="uid")]
pub struct SysUser {
pub uid: Option<String>,
pub account: Option<String>,
pub password: Option<String>,
pub name: Option<String>,
pub del: Option<i32>,
pub create_time: Option<NaiveDateTime>,
}
from rbatis.
#[derive(Serialize, Deserialize, Clone, Debug)] pub struct SysUser { pub id: Option<String>, pub account: Option<String>, pub password: Option<String>, pub name: Option<String>, pub del: Option<i32>, pub create_time: Option<NaiveDateTime>, } impl CRUDEnable for SysUser { type IdType = String; }
对于上面的简化
我提供下面思路,我觉得可行:
1、简化版本,无需自定义
#[derive(Serialize, Deserialize, Clone, Debug, CRUDEnable)] pub struct SysUser { pub id: Option<String>, pub account: Option<String>, pub password: Option<String>, pub name: Option<String>, pub del: Option<i32>, pub create_time: Option<NaiveDateTime>, }
2、需自定义
#[derive(Serialize, Deserialize, Clone, Debug, CRUDEnable)] #[rbatis(table="t_user", id="uid")] pub struct SysUser { pub uid: Option<String>, pub account: Option<String>, pub password: Option<String>, pub name: Option<String>, pub del: Option<i32>, pub create_time: Option<NaiveDateTime>, }
1.5.0版本,现已实现 #[derive(CRUDEnable)] 功能。
上面提到的第二条,采取 手动实现 impl CRUDEnable for SysUser { } 这种形式
from rbatis.
@ycvbcvfu great idea
from rbatis.
Related Issues (20)
- How to determine whether the select result is no record found? HOT 12
- no method named `str` found for reference `&rbs::Value` in the current scope HOT 1
- In the generated update and insert statements, use ``` to escape the fields HOT 9
- When the DateTime field is read from the database, it will always be UTC. HOT 2
- Is there a macro to modify the name of the field in sturct? HOT 4
- After using rbatis 4, it was found that it is not compatible with the criterion bench HOT 3
- How to use the function that supports sqlite to set password? HOT 1
- How to use the function that supports sqlite to set password? HOT 7
- Transactton Token error: 'Incorrect syntax near 'begin'.' on server HOT 5
- Removed local dependencies. Re-cargo build reports an error! Version rbatis: 4.5.11 HOT 5
- method `set_timeout` is not a member of trait `Pool` HOT 17
- add duckdb support HOT 4
- Hello, I have encountered a question: functions in traits cannot be declared `async` HOT 2
- When using enumeration, can it support automatic conversion to integer when saving or updating, and automatically convert integer to enumeration when selecting? HOT 2
- Intermittent Delays in Query Execution After Periods of Inactivity HOT 4
- MSSQL using transactions error: token error: 'Incorrect syntax near 'begin'.' on server MSSQL2016 executing on line 1 (code: 102, state: 1, class: 15) HOT 2
- crud insert is error when the primary key column name is not id
- html_sql can't trim uppercase "and|or" after where HOT 1
- htmlsql_select_page field is filtered problem HOT 2
- The json field of the database is returned as an escaped string HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rbatis.