db, err := bolt.Open("mydb.db", 0600, nil) if err != nil { log.Fatal(err) } defer db.Close() err = db.Update(func(tx *bolt.Tx) error { bucket := tx.Bucket([]byte("myBucket")) err := bucket.Delete([]byte("myKey")) if err != nil { return err } return nil }) if err != nil { log.Fatal(err) }
err = db.Batch(func(tx *bolt.Tx) error { bucket := tx.Bucket([]byte("myBucket")) err := bucket.Delete([]byte("myKey1")) if err != nil { return err } err = bucket.Delete([]byte("myKey2")) if err != nil { return err } return nil }) if err != nil { log.Fatal(err) }This code deletes multiple key-value pairs from a bucket in a single transaction using the Batch method.