|
1 | 1 | # Gorm-plus
|
| 2 | + |
2 | 3 | Gorm-plus是基于Gorm的增强版,类似Mybatis-plus语法。
|
3 | 4 | ## 特性
|
4 | 5 | - [x] 无侵入:只做增强不做改变
|
@@ -270,4 +271,42 @@ func init() {
|
270 | 271 | for _, student := range page.Records {
|
271 | 272 | log.Printf("student:%v\n", student)
|
272 | 273 | }
|
| 274 | +~~~ |
| 275 | +##### 根据ID更新 |
| 276 | +~~~go |
| 277 | + student := Student{ID: 3, Name: "lisi"} |
| 278 | + student.Name = "lisi" |
| 279 | + resultDb := gplus.UpdateById[Student](&student) |
| 280 | + log.Printf("error:%v\n", resultDb.Error) |
| 281 | + log.Printf("RowsAffected:%v\n", resultDb.RowsAffected) |
| 282 | +~~~ |
| 283 | +##### 根据条件更新 |
| 284 | +~~~go |
| 285 | + query, model := gplus.NewQuery[Student]() |
| 286 | + query.Eq(&model.Name, "zhangsan").Set(&model.Age, 30) |
| 287 | + resultDb := gplus.Update[Student](query) |
| 288 | + log.Printf("error:%v\n", resultDb.Error) |
| 289 | + log.Printf("RowsAffected:%v\n", resultDb.RowsAffected) |
| 290 | +~~~ |
| 291 | +##### 根据ID删除 |
| 292 | +~~~go |
| 293 | + resultDb := gplus.DeleteById[Student](4) |
| 294 | + log.Printf("error:%v\n", resultDb.Error) |
| 295 | + log.Printf("RowsAffected:%v\n", resultDb.RowsAffected) |
| 296 | +~~~ |
| 297 | +##### 根据多个ID删除 |
| 298 | +~~~go |
| 299 | + var ids = []int{5, 6} |
| 300 | + resultDb := gplus.DeleteByIds[Student](ids) |
| 301 | + log.Printf("error:%v\n", resultDb.Error) |
| 302 | + log.Printf("RowsAffected:%v\n", resultDb.RowsAffected) |
| 303 | +~~~ |
| 304 | +##### 根据条件删除 |
| 305 | +~~~go |
| 306 | + query, model := gplus.NewQuery[Student]() |
| 307 | + query.Eq(&model.Name, "lisi") |
| 308 | + resultDb := gplus.Delete(query) |
| 309 | + log.Printf("error:%v\n", resultDb.Error) |
| 310 | + log.Printf("RowsAffected:%v\n", resultDb.RowsAffected) |
| 311 | +======= |
273 | 312 | ~~~
|
0 commit comments