Skip to content

Commit c053925

Browse files
committed
add BaseMpper
1 parent 74cc593 commit c053925

File tree

5 files changed

+66
-17
lines changed

5 files changed

+66
-17
lines changed

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,36 @@ gobatis-plus -i github.com/xfali/gobatis-plus/example -o tmp
1313
## Package
1414
1. Add doc.go to enable gobatis in package
1515
```
16-
// gobatis:enable
16+
// +gobatis:enable
1717
package example
1818
```
1919
2. add your code
2020
```
21-
// gobatis:data
21+
// +gobatis:data:tablename=tbl_user
2222
type UserDo struct {
23-
UserId int64 `tableId:"user_id,idType=auto"`
24-
UserName string `tableField:"user_name"`
25-
Status int8 `tableField:"status" tableLogic:"0,delval=1"`
26-
CreateTime time.Time `tableField:"create_time,fill=insert"`
27-
RecVersion uint64 `tableRecVer:"rec_var"`
23+
// +gobatis:tableid:value=user_id,idType=auto
24+
UserId int64
25+
26+
// +gobatis:tablefield:value=user_name
27+
UserName string
28+
29+
// +gobatis:tablefield:value=status
30+
// +gobatis:tablelogic:value=0,delval=1
31+
Status int8
32+
33+
// +gobatis:tablefield:value=create_time,fill=insert
34+
CreateTime time.Time
35+
36+
// +gobatis:tablefield:value=rec_var
37+
// +gobatis:version
38+
RecVersion uint64
2839
}
2940
30-
// gobatis:mapper
41+
// +gobatis:mapper
3142
type UserMapper interface {
32-
// gobatis:select="select * from "
33-
34-
Insert(vo ...UserDo) (err error)
43+
mapper.BaseMapper[UserDo]
44+
45+
// +gobatis:select="select * from tbl_user where id = #{UserDo.UserId}"
46+
Select(user UserDo) (users []UserDo, err error)
3547
}
3648
```

example/example.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
package example
77

8-
import "time"
8+
import (
9+
"github.com/xfali/gobatis-plus/pkg/mapper"
10+
"time"
11+
)
912

10-
// +gobatis:data
13+
// +gobatis:data:tablename=tbl_user
1114
type UserDo struct {
1215
// +gobatis:tableid:value=user_id,idType=auto
1316
UserId int64
@@ -29,8 +32,8 @@ type UserDo struct {
2932

3033
// +gobatis:mapper
3134
type UserMapper interface {
32-
// +gobatis:select="select * from tbl_user where id = #{UserDo.UserId}"
33-
Select(vo UserDo) ([]UserDo, error)
35+
mapper.BaseMapper[UserDo]
3436

35-
Insert(vo ...UserDo) (err error)
37+
// +gobatis:select="select * from tbl_user where id = #{UserDo.UserId}"
38+
Select(user UserDo) (users []UserDo, err error)
3639
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/xfali/gobatis-plus
22

3-
go 1.16
3+
go 1.18
44

55
require (
66
github.com/spf13/pflag v1.0.5

pkg/mapper/base.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2022, Xiongfa Li.
2+
// All right reserved.
3+
// @author xiongfa.li
4+
// @version V1.0
5+
// Description:
6+
7+
package mapper
8+
9+
type BaseMapper[T any] interface {
10+
Insert(entity T) int64
11+
12+
InsertBatch(entities ...T) (int64, int64)
13+
14+
DeleteById(id any) int64
15+
16+
DeleteBatchIds(ids []any) int64
17+
18+
UpdateById(entity T) int64
19+
20+
SelectById(id any) T
21+
22+
SelectBatchIds(ids []any) []T
23+
24+
SelectOne(entity T) T
25+
26+
SelectCount(entity T) int64
27+
}

pkg/mapper/wapper.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (C) 2022, Xiongfa Li.
2+
// All right reserved.
3+
// @author xiongfa.li
4+
// @version V1.0
5+
// Description:
6+
7+
package mapper

0 commit comments

Comments
 (0)