You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vartDB appmodels.TaskDBiferr=getgDB().WithContext(ctx).Table("task_db").Where("task_id = ?", taskID).First(&tDB).Error; err!=nil {
returnnil, err
}
// The following is printed by gorm logger - level INFO// SELECT * FROM "task_db" WHERE task_id = '37-5' AND "task_db"."deleted_at" IS NULL ORDER BY "task_db"."task_id" LIMIT 1
This function return an err != nil if record not exist.
Find function:
Code:
vartDB appmodels.TaskDBiferr=getgDB().WithContext(ctx).Table("task_db").Where("task_id = ?", taskID).Find(&tDB).Error; err!=nil {
returnnil, err
}
// The following is printed by gorm logger - level INFO// SELECT * FROM "task_db" WHERE task_id = '37-5' AND "task_db"."deleted_at" IS NULL
This function return an err == nil if record not exist.
Conclusion:
While the first function can be used but it will cost some overhead for ordering the result.
I think the reason is Find function update the DeletedAt fields while First funtion doesn't.
The text was updated successfully, but these errors were encountered:
GORM Playground Link
go-gorm/playground#93
Description
First function:
Code:
This function return an err != nil if record not exist.
Find function:
Code:
This function return an err == nil if record not exist.
Conclusion:
While the first function can be used but it will cost some overhead for ordering the result.
I think the reason is Find function update the DeletedAt fields while First funtion doesn't.
The text was updated successfully, but these errors were encountered: