@@ -86,6 +86,16 @@ func Delete[T any](q *Query[T]) *gorm.DB {
86
86
return resultDb
87
87
}
88
88
89
+ func DeleteByMap [T any ](q * Query [T ]) * gorm.DB {
90
+ for k , v := range q .ConditionMap {
91
+ columnName := q .getColumnName (k )
92
+ q .Eq (columnName , v )
93
+ }
94
+ var entity T
95
+ resultDb := gormDb .Where (q .QueryBuilder .String (), q .QueryArgs ... ).Delete (& entity )
96
+ return resultDb
97
+ }
98
+
89
99
func UpdateById [T any ](entity * T ) * gorm.DB {
90
100
resultDb := gormDb .Model (entity ).Updates (entity )
91
101
return resultDb
@@ -130,6 +140,20 @@ func SelectListModel[T any, R any](q *Query[T]) ([]*R, *gorm.DB) {
130
140
return results , resultDb
131
141
}
132
142
143
+ func SelectListByMap [T any ](q * Query [T ]) ([]* T , * gorm.DB ) {
144
+ resultDb := buildCondition (q )
145
+ var results []* T
146
+ resultDb .Find (& results )
147
+ return results , resultDb
148
+ }
149
+
150
+ func SelectListMaps [T any ](q * Query [T ]) ([]map [string ]any , * gorm.DB ) {
151
+ resultDb := buildCondition (q )
152
+ var results []map [string ]any
153
+ resultDb .Find (& results )
154
+ return results , resultDb
155
+ }
156
+
133
157
func SelectPage [T any ](page * Page [T ], q * Query [T ]) (* Page [T ], * gorm.DB ) {
134
158
total , countDb := SelectCount [T ](q )
135
159
if countDb .Error != nil {
@@ -156,6 +180,21 @@ func SelectPageModel[T any, R any](page *Page[R], q *Query[T]) (*Page[R], *gorm.
156
180
return page , resultDb
157
181
}
158
182
183
+ func SelectPageMaps [T any ](page * Page [map [string ]any ], q * Query [T ]) (* Page [map [string ]any ], * gorm.DB ) {
184
+ total , countDb := SelectCount [T ](q )
185
+ if countDb .Error != nil {
186
+ return page , countDb
187
+ }
188
+ page .Total = total
189
+ resultDb := buildCondition (q )
190
+ var results []map [string ]any
191
+ resultDb .Scopes (paginate (page )).Find (& results )
192
+ for _ , m := range results {
193
+ page .Records = append (page .Records , & m )
194
+ }
195
+ return page , resultDb
196
+ }
197
+
159
198
func SelectCount [T any ](q * Query [T ]) (int64 , * gorm.DB ) {
160
199
var count int64
161
200
resultDb := buildCondition (q )
@@ -204,6 +243,15 @@ func buildCondition[T any](q *Query[T]) *gorm.DB {
204
243
resultDb .Where (q .QueryBuilder .String (), q .QueryArgs ... )
205
244
}
206
245
246
+ if len (q .ConditionMap ) > 0 {
247
+ var condMap = make (map [string ]any )
248
+ for k , v := range q .ConditionMap {
249
+ columnName := q .getColumnName (k )
250
+ condMap [columnName ] = v
251
+ }
252
+ resultDb .Where (condMap )
253
+ }
254
+
207
255
if q .OrderBuilder .Len () > 0 {
208
256
resultDb .Order (q .OrderBuilder .String ())
209
257
}
0 commit comments