@@ -175,7 +175,7 @@ func Exec(ctx context.Context, sqlAndArgs ...any) (sql.Result, error) {
175175
176176func Get [T any ](ctx context.Context , cond builder.Cond ) (object * T , exist bool , err error ) {
177177 if ! cond .IsValid () {
178- return nil , false , ErrConditionRequired {}
178+ panic ( "cond is invalid in db.Get(ctx, cond). This should not be possible." )
179179 }
180180
181181 var bean T
@@ -201,7 +201,7 @@ func GetByID[T any](ctx context.Context, id int64) (object *T, exist bool, err e
201201
202202func Exist [T any ](ctx context.Context , cond builder.Cond ) (bool , error ) {
203203 if ! cond .IsValid () {
204- return false , ErrConditionRequired {}
204+ panic ( "cond is invalid in db.Exist(ctx, cond). This should not be possible." )
205205 }
206206
207207 var bean T
@@ -213,16 +213,36 @@ func ExistByID[T any](ctx context.Context, id int64) (bool, error) {
213213 return GetEngine (ctx ).ID (id ).NoAutoCondition ().Exist (& bean )
214214}
215215
216+ // DeleteByID deletes the given bean with the given ID
217+ func DeleteByID [T any ](ctx context.Context , id int64 ) (int64 , error ) {
218+ var bean T
219+ return GetEngine (ctx ).ID (id ).NoAutoCondition ().NoAutoTime ().Delete (& bean )
220+ }
221+
222+ func DeleteByIDs [T any ](ctx context.Context , ids ... int64 ) error {
223+ if len (ids ) == 0 {
224+ return nil
225+ }
226+
227+ var bean T
228+ _ , err := GetEngine (ctx ).In ("id" , ids ).NoAutoCondition ().NoAutoTime ().Delete (& bean )
229+ return err
230+ }
231+
232+ func Delete [T any ](ctx context.Context , opts FindOptions ) (int64 , error ) {
233+ if opts == nil || ! opts .ToConds ().IsValid () {
234+ panic ("opts are empty or invalid in db.Delete(ctx, opts). This should not be possible." )
235+ }
236+
237+ var bean T
238+ return GetEngine (ctx ).Where (opts .ToConds ()).NoAutoCondition ().NoAutoTime ().Delete (& bean )
239+ }
240+
216241// DeleteByBean deletes all records according non-empty fields of the bean as conditions.
217242func DeleteByBean (ctx context.Context , bean any ) (int64 , error ) {
218243 return GetEngine (ctx ).Delete (bean )
219244}
220245
221- // DeleteByID deletes the given bean with the given ID
222- func DeleteByID (ctx context.Context , id int64 , bean any ) (int64 , error ) {
223- return GetEngine (ctx ).ID (id ).NoAutoCondition ().NoAutoTime ().Delete (bean )
224- }
225-
226246// FindIDs finds the IDs for the given table name satisfying the given condition
227247// By passing a different value than "id" for "idCol", you can query for foreign IDs, i.e. the repo IDs which satisfy the condition
228248func FindIDs (ctx context.Context , tableName , idCol string , cond builder.Cond ) ([]int64 , error ) {
0 commit comments