Skip to content

Commit 8222550

Browse files
authored
doc: update readme (#16)
* doc: update README.md * doc: update README.md * fix: fix updateById bug * doc: update README.md * doc: update README.md
1 parent 0d84687 commit 8222550

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Gorm-plus
2+
23
Gorm-plus是基于Gorm的增强版,类似Mybatis-plus语法。
34
## 特性
45
- [x] 无侵入:只做增强不做改变
@@ -270,4 +271,42 @@ func init() {
270271
for _, student := range page.Records {
271272
log.Printf("student:%v\n", student)
272273
}
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+
=======
273312
~~~

0 commit comments

Comments
 (0)