Comments (9)
就是在entity的基础上再额外设置某个字段是null值该怎么做呢(现在的逻辑应该是None字段不做更改的吧)
什么意思?不是用Option 类似这种成员变量就行了吗。
let mut rb = init_rbatis().await;
let w = Wrapper::new(&rb.driver_type().unwrap()).eq("id", "1").check().unwrap();
let r: Result<Option<BizActivity>, Error> = rb.fetch_by_wrapper("", &w).await;
不理解,你上代码吧
from rbatis.
rb.save("", &activity).await;在这个基础上怎么额外设置activity某个字段是null?还是说None也会更新字段?
from rbatis.
就是mybatis里entity的ID如果是null则是insert,非null则update,然后update默认不会去更新是null的字段,这样就能很方便的对某条记录局部更新,但是有的时候希望以这种方式更新某个字段为null就需要额外做一些操作,想问下这里的这个额外操作是什么?
from rbatis.
就是mybatis里entity的ID如果是null则是insert,非null则update,然后update默认不会去更新是null的字段,这样就能很方便的对某条记录局部更新,但是有的时候希望以这种方式更新某个字段为null就需要额外做一些操作,想问下这里的这个额外操作是什么?
这里是类似mybatis一样的,null字段过滤,只更新非null的字段
参考新版本 example/crud_test.rs
let activity = BizActivity {
id: Some("12312".to_string()),
name: None,
pc_link: None,
h5_link: None,
pc_banner_img: None,
h5_banner_img: None,
sort: None,
status: Some(1),
remark: None,
create_time: Some("2020-02-09 00:00:00".to_string()),
version: Some(1),
delete_flag: Some(1),
};
let r = rb.update_by_id("", &activity).await;
sql生成的就是
2020-07-19T21:18:56.765193500+08:00 INFO rbatis::rbatis - [rbatis] Exec ==> UPDATE biz_activity SET create_time = ? , delete_flag = ? , status = ? , version = ? WHERE id = ?
2020-07-19T21:18:56.768193300+08:00 INFO rbatis::rbatis - [rbatis] Args ==> ["2020-02-09 00:00:00",1,1,1,"12312"]
2020-07-19T21:18:56.808219700+08:00 INFO rbatis::rbatis - [rbatis] Affected <== 1
from rbatis.
就是mybatis里entity的ID如果是null则是insert,非null则update,然后update默认不会去更新是null的字段,这样就能很方便的对某条记录局部更新,但是有的时候希望以这种方式更新某个字段为null就需要额外做一些操作,想问下这里的这个额外操作是什么?
框架默认已经自带了大部分常用操作,如果不满足,你可以用Wrapper 自定义sql
例如 修改某个字段为null:
let activity = BizActivity {
id: Some("12312".to_string()),
name: None,
pc_link: None,
h5_link: None,
pc_banner_img: None,
h5_banner_img: None,
sort: None,
status: Some(1),
remark: None,
create_time: Some("2020-02-09 00:00:00".to_string()),
version: Some(1),
delete_flag: Some(1),
};
let w = Wrapper::new(&DriverType::Mysql)
.set_sql("update table set del_falg = NULL where ")
.eq("id", 1)
.check().unwrap();
let r = rb.update_by_wrapper("", &activity, &w).await;
如果是涉及到 非常复杂的join操作
那么还是用xml或者py定义吧
例如
let py = r#"
SELECT * FROM biz_activity
WHERE delete_flag = #{delete_flag}
if name != null:
AND name like #{name+'%'}
if ids != null:
AND id in (
trim ',':
for item in ids:
#{item},
)"#;
let data: serde_json::Value = rb.py_fetch("", py, &json!({ "delete_flag": 1 })).await.unwrap();
from rbatis.
mybatis的做法是提供updateByPrimaryKeySelective和updateByPrimaryKey两个方法吧。保存空值和不更新空值两个方法的常用程度基本差不多
from rbatis.
mybatis的做法是提供updateByPrimaryKeySelective和updateByPrimaryKey两个方法吧。保存空值和不更新空值两个方法的常用程度基本差不多
不错的主意,到时候新版本,提供更新空值的常用方法
from rbatis.
请问咋样了呀?可以咋做更新值为空啊?
from rbatis.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
How is it? How can the update value be empty?
from rbatis.
Related Issues (20)
- 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
- Setting result error using py_sql with single result HOT 1
- Is there any synchronized Chinese document? HOT 3
- Unable to update column to null.
- Prior code to get SQLite version using sqlite_version() works. Now broken. [Solved Manually. See comments] HOT 2
- test_decode_time_zone error
- Variable `recordsValue` should have snake_case name, e.g. `records_value` HOT 5
- Common field processing issues HOT 2
- The document needs to be updated HOT 2
- How to dynamically specify schema HOT 14
- add return primary key value in postgresql HOT 1
- How to use tracing log in rbatis-v4 version HOT 2
- field value with json string, return invalid type: map, expected String error HOT 2
- Setting the maximum connection pool doesn't work well HOT 3
- Hello, I encountered an issue with a plugin dynamically modifying SQL HOT 4
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.