Skip to content

Commit

Permalink
add delete by key for tx
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed Apr 13, 2017
1 parent 459cbf4 commit 01316e3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,23 @@ func (tx *Tx) SaveModels(src interface{}) ([]*datastore.PendingKey, error) {
}
return tx.PutModels(src)
}

// DeleteByKey deletes a model by key
func (tx *Tx) DeleteByKey(key *datastore.Key) error {
err := tx.Delete(key)
if key != nil && !key.Incomplete() {
tx.invalidateKeys = append(tx.invalidateKeys, key)
}
return err
}

// DeleteByKeys deletes models by keys
func (tx *Tx) DeleteByKeys(keys []*datastore.Key) error {
err := tx.DeleteMulti(keys)
for _, key := range keys {
if key != nil && !key.Incomplete() {
tx.invalidateKeys = append(tx.invalidateKeys, key)
}
}
return err
}

0 comments on commit 01316e3

Please sign in to comment.