-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE
To prevent the operation from waiting for other transactions to commit, use either the NOWAIT or SKIP LOCKED option. With NOWAIT, the statement reports an error, rather than waiting, if a selected row cannot be locked immediately
func (e *EquipmentRepo) LockByID(ctx context.Context, id int) error {
err := e.db.Model(ctx, &domain.Equipment{}).
Where("id = ?", id).
For("UPDATE NO WAIT").
Select()
if err == pg.ErrNoRows {
return nil
}
return err
}Metadata
Metadata
Assignees
Labels
No labels