@@ -9,6 +9,7 @@ go get github.com/gorm-plus/gorm-plus
9
9
10
10
``` go
11
11
12
+
12
13
func init () {
13
14
dsn := " root:root-abcd-1234@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"
14
15
var err error
@@ -27,14 +28,14 @@ type Test1 struct {
27
28
28
29
func TestSave (t *testing .T ) {
29
30
test1 := Test1{Code: " D1" , Price: 100 }
30
- resultDb := mapper .Insert (&test1)
31
+ resultDb := gormplus .Insert (&test1)
31
32
fmt.Println (resultDb)
32
33
fmt.Println (test1)
33
34
}
34
35
35
36
func TestSaveMigrate (t *testing .T ) {
36
37
test1 := Test1{Code: " D2" , Price: 100 }
37
- resultDb , err := mapper .InsertMigrate (&test1)
38
+ resultDb , err := gormplus .InsertMigrate (&test1)
38
39
if err != nil {
39
40
fmt.Println (err)
40
41
}
@@ -45,7 +46,7 @@ func TestSaveMigrate(t *testing.T) {
45
46
func TestBatchSave (t *testing .T ) {
46
47
test1 := Test1{Code: " D3" , Price: 100 }
47
48
test2 := Test1{Code: " D4" , Price: 100 }
48
- resultDb := mapper .InsertBatch (&test1, &test2)
49
+ resultDb := gormplus .InsertBatch (&test1, &test2)
49
50
fmt.Println (resultDb)
50
51
fmt.Println (test1)
51
52
fmt.Println (test2)
@@ -54,7 +55,7 @@ func TestBatchSave(t *testing.T) {
54
55
func TestSaveBatchMigrate (t *testing .T ) {
55
56
test1 := Test1{Code: " D5" , Price: 100 }
56
57
test2 := Test1{Code: " D6" , Price: 100 }
57
- resultDb , err := mapper .InsertBatchMigrate (&test1, &test2)
58
+ resultDb , err := gormplus .InsertBatchMigrate (&test1, &test2)
58
59
if err != nil {
59
60
fmt.Println (err)
60
61
}
@@ -64,68 +65,68 @@ func TestSaveBatchMigrate(t *testing.T) {
64
65
}
65
66
66
67
func TestDeleteById (t *testing .T ) {
67
- resultDb := mapper .DeleteById [Test1](1 )
68
+ resultDb := gormplus .DeleteById [Test1](1 )
68
69
fmt.Println (resultDb)
69
70
}
70
71
71
72
func TestDeleteByIds (t *testing .T ) {
72
- resultDb := mapper .DeleteByIds [Test1](4 , 5 )
73
+ resultDb := gormplus .DeleteByIds [Test1](4 , 5 )
73
74
fmt.Println (resultDb)
74
75
}
75
76
76
77
func TestDelete (t *testing .T ) {
77
- q := mapper .Query [Test1]{}
78
+ q := gormplus .Query [Test1]{}
78
79
q.Eq (" code" , " D1" ).Eq (" price" , 100 )
79
- resultDb := mapper .Delete (&q)
80
+ resultDb := gormplus .Delete (&q)
80
81
fmt.Println (resultDb)
81
82
}
82
83
83
84
func TestUpdateById (t *testing .T ) {
84
85
test1 := Test1{Code: " 777" }
85
- resultDb := mapper .UpdateById (6 , &test1)
86
+ resultDb := gormplus .UpdateById (6 , &test1)
86
87
fmt.Println (resultDb)
87
88
}
88
89
89
90
func TestUpdate (t *testing .T ) {
90
- q := mapper .Query [Test1]{}
91
+ q := gormplus .Query [Test1]{}
91
92
q.Eq (" code" , " D42" ).Eq (" price" , 100 )
92
93
test1 := Test1{Code: " 888" }
93
- resultDb := mapper .Update (&q, &test1)
94
+ resultDb := gormplus .Update (&q, &test1)
94
95
fmt.Println (resultDb)
95
96
}
96
97
97
98
func TestSelectById (t *testing .T ) {
98
- db , result := mapper .SelectById [Test1](1 )
99
+ db , result := gormplus .SelectById [Test1](1 )
99
100
fmt.Println (db)
100
101
fmt.Println (result)
101
102
}
102
103
103
104
func TestSelectByIds (t *testing .T ) {
104
- db , result := mapper .SelectByIds [Test1](1 , 2 )
105
+ db , result := gormplus .SelectByIds [Test1](1 , 2 )
105
106
fmt.Println (db)
106
107
fmt.Println (result)
107
108
}
108
109
109
110
func TestSelectOne (t *testing .T ) {
110
- q := mapper .Query [Test1]{}
111
+ q := gormplus .Query [Test1]{}
111
112
q.Eq (" code" , " D42" ).Eq (" price" , 100 )
112
- db , result := mapper .SelectOne (&q)
113
+ db , result := gormplus .SelectOne (&q)
113
114
fmt.Println (db)
114
115
fmt.Println (result)
115
116
}
116
117
117
118
func TestSelectList (t *testing .T ) {
118
- q := mapper .Query [Test1]{}
119
+ q := gormplus .Query [Test1]{}
119
120
q.Eq (" price" , 100 )
120
- db , result := mapper .SelectList (&q)
121
+ db , result := gormplus .SelectList (&q)
121
122
fmt.Println (db.RowsAffected )
122
123
fmt.Println (result)
123
124
}
124
125
125
126
func TestSelectCount (t *testing .T ) {
126
- q := mapper .Query [Test1]{}
127
+ q := gormplus .Query [Test1]{}
127
128
q.Eq (" price" , 100 )
128
- db , count := mapper .SelectCount (&q)
129
+ db , count := gormplus .SelectCount (&q)
129
130
fmt.Println (db)
130
131
fmt.Println (count)
131
132
}
0 commit comments