Skip to content

Commit

Permalink
add lock in create node
Browse files Browse the repository at this point in the history
  • Loading branch information
calebx committed Dec 25, 2020
1 parent 892052b commit eaa4b3e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nested_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ func parseNode(db *gorm.DB, source interface{}) (tx *gorm.DB, item nodeItem, err
// ```nestedset.Create(db, &Category{...}, &parent)``` will create a new category under parent node as its last child
func Create(db *gorm.DB, source, parent interface{}) error {
return db.Transaction(func(db *gorm.DB) (err error) {
// lock table
lockRst := make(map[string]interface{}, 0)
err = db.Model(source).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&lockRst).Error
if err != nil {
return nil
}

tx, target, err := parseNode(db, source)
if err != nil {
return err
Expand Down

0 comments on commit eaa4b3e

Please sign in to comment.