@@ -21,82 +21,80 @@ import (
21
21
"gorm.io/gorm"
22
22
)
23
23
24
- type CommonDao [T any , K PrimaryKey ] struct {
25
- pkColumn string
26
- }
24
+ type CommonDao [T any ] struct {}
27
25
28
- func NewCommonDao [T any , K PrimaryKey ](pk string ) * CommonDao [T , K ] {
29
- return & CommonDao [T , K ]{ pkColumn : pk }
26
+ func NewCommonDao [T any ](pk string ) * CommonDao [T ] {
27
+ return & CommonDao [T ]{ }
30
28
}
31
29
32
- func (service CommonDao [T , K ]) Db () * gorm.DB {
30
+ func (service CommonDao [T ]) Db () * gorm.DB {
33
31
return gormDb
34
32
}
35
33
36
- func (service CommonDao [T , K ]) Save (entity * T ) * gorm.DB {
34
+ func (service CommonDao [T ]) Save (entity * T ) * gorm.DB {
37
35
return Insert [T ](entity )
38
36
}
39
37
40
- func (service CommonDao [T , K ]) SaveBatch (entities []* T ) * gorm.DB {
38
+ func (service CommonDao [T ]) SaveBatch (entities []* T ) * gorm.DB {
41
39
return InsertBatch [T ](entities )
42
40
}
43
41
44
- func (service CommonDao [T , K ]) SaveBatchSize (entities []* T , batchSize int ) * gorm.DB {
42
+ func (service CommonDao [T ]) SaveBatchSize (entities []* T , batchSize int ) * gorm.DB {
45
43
return InsertBatchSize [T ](entities , batchSize )
46
44
}
47
45
48
- func (service CommonDao [T , K ]) RemoveById (id K ) * gorm.DB {
49
- return DeleteById [T , K ](id , service . pkColumn )
46
+ func (service CommonDao [T ]) RemoveById (id any ) * gorm.DB {
47
+ return DeleteById [T ](id )
50
48
}
51
49
52
- func (service CommonDao [T , K ]) RemoveByIds (ids []K ) * gorm.DB {
53
- return DeleteByIds [T , K ](ids )
50
+ func (service CommonDao [T ]) RemoveByIds (ids []any ) * gorm.DB {
51
+ return DeleteByIds [T ](ids )
54
52
}
55
53
56
- func (service CommonDao [T , K ]) Remove (q * Query [T ]) * gorm.DB {
54
+ func (service CommonDao [T ]) Remove (q * Query [T ]) * gorm.DB {
57
55
return Delete [T ](q )
58
56
}
59
57
60
- func (service CommonDao [T , K ]) UpdateById (entity * T , id K ) * gorm.DB {
61
- return UpdateById [T , K ](entity , id , service . pkColumn )
58
+ func (service CommonDao [T ]) UpdateById (entity * T , id any ) * gorm.DB {
59
+ return UpdateById [T ](entity , id )
62
60
}
63
61
64
- func (service CommonDao [T , K ]) Update (q * Query [T ]) * gorm.DB {
62
+ func (service CommonDao [T ]) Update (q * Query [T ]) * gorm.DB {
65
63
return Update [T ](q )
66
64
}
67
65
68
- func (service CommonDao [T , K ]) GetById (id K ) (* T , * gorm.DB ) {
69
- return SelectById [T , K ](id )
66
+ func (service CommonDao [T ]) GetById (id any ) (* T , * gorm.DB ) {
67
+ return SelectById [T ](id )
70
68
}
71
69
72
- func (service CommonDao [T , K ]) GetOne (q * Query [T ]) (* T , * gorm.DB ) {
70
+ func (service CommonDao [T ]) GetOne (q * Query [T ]) (* T , * gorm.DB ) {
73
71
return SelectOne [T ](q )
74
72
}
75
73
76
- func (service CommonDao [T , K ]) ListAll () ([]* T , * gorm.DB ) {
74
+ func (service CommonDao [T ]) ListAll () ([]* T , * gorm.DB ) {
77
75
return SelectList [T ](nil )
78
76
}
79
77
80
- func (service CommonDao [T , K ]) List (q * Query [T ]) ([]* T , * gorm.DB ) {
78
+ func (service CommonDao [T ]) List (q * Query [T ]) ([]* T , * gorm.DB ) {
81
79
return SelectList [T ](q )
82
80
}
83
81
84
- func (service CommonDao [T , K ]) ListByIds (ids []K ) ([]* T , * gorm.DB ) {
85
- return SelectByIds [T , K ](ids )
82
+ func (service CommonDao [T ]) ListByIds (ids []any ) ([]* T , * gorm.DB ) {
83
+ return SelectByIds [T ](ids )
86
84
}
87
85
88
- func (service CommonDao [T , K ]) PageAll (page * Page [T ]) (* Page [T ], * gorm.DB ) {
86
+ func (service CommonDao [T ]) PageAll (page * Page [T ]) (* Page [T ], * gorm.DB ) {
89
87
return SelectPage [T ](page , nil )
90
88
}
91
89
92
- func (service CommonDao [T , K ]) Page (page * Page [T ], q * Query [T ]) (* Page [T ], * gorm.DB ) {
90
+ func (service CommonDao [T ]) Page (page * Page [T ], q * Query [T ]) (* Page [T ], * gorm.DB ) {
93
91
return SelectPage [T ](page , q )
94
92
}
95
93
96
- func (service CommonDao [T , K ]) CountAll () (int64 , * gorm.DB ) {
94
+ func (service CommonDao [T ]) CountAll () (int64 , * gorm.DB ) {
97
95
return SelectCount [T ](nil )
98
96
}
99
97
100
- func (service CommonDao [T , K ]) Count (q * Query [T ]) (int64 , * gorm.DB ) {
98
+ func (service CommonDao [T ]) Count (q * Query [T ]) (int64 , * gorm.DB ) {
101
99
return SelectCount [T ](q )
102
100
}
0 commit comments