Skip to content

Commit 9b3c041

Browse files
committed
refactor: Modify mapper.go to dao.go
1 parent 3800563 commit 9b3c041

File tree

13 files changed

+71
-14
lines changed

13 files changed

+71
-14
lines changed

cmd/gplus/gen.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ func buildGenFile(root *loader.Package, allStructInfos []StructInfo) *jen.File {
8989
genFile.Id("}").Id("{")
9090
for i, field := range s.Fields {
9191
tag := s.FieldTags[i]
92-
// todo Need to optimize
9392
newTag := strings.ReplaceAll(tag, "gorm:", "")
9493
newTag = strings.ReplaceAll(newTag, "\"", "")
9594
tagSetting := schema.ParseTagSetting(newTag, ";")
File renamed without changes.
File renamed without changes.

example/list_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package example
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"testing"
7+
)
8+
9+
func TestList(t *testing.T) {
10+
userDao := NewUserDao[User]()
11+
list, resultDb := userDao.List(nil)
12+
log.Println(resultDb.RowsAffected)
13+
for _, v := range list {
14+
marshal, _ := json.Marshal(v)
15+
log.Println(string(marshal))
16+
}
17+
}

example/save_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package example
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
func TestSave(t *testing.T) {
9+
userDao := NewUserDao[User]()
10+
user1 := &User{Username: "zhangsan1", Password: "123456", Age: 18, Score: 12, Dept: "导弹部门"}
11+
resultDb := userDao.Save(user1)
12+
fmt.Println(resultDb.RowsAffected)
13+
}
File renamed without changes.
File renamed without changes.

example/user.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package example
22

3-
import "time"
3+
import (
4+
"time"
5+
)
46

57
// +gplus:column=true
68

@@ -20,15 +22,3 @@ type User struct {
2022
func (User) TableName() string {
2123
return "Users"
2224
}
23-
24-
// +gplus:column=true
25-
26-
type Clazz struct {
27-
ID int64 `gorm:"primaryKey"`
28-
Name string
29-
Count string
30-
TeacherName string
31-
HouseNumber int `gorm:"column:house"`
32-
CreatedAt time.Time
33-
UpdatedAt time.Time
34-
}

example/user_dao.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package example
2+
3+
import "github.com/gorm-plus/gorm-plus/gormplus"
4+
5+
type UserDao[T any] struct {
6+
gormplus.CommonDao[T]
7+
}
8+
9+
func NewUserDao[T any]() *UserDao[T] {
10+
return &UserDao[T]{}
11+
}
File renamed without changes.

0 commit comments

Comments
 (0)