0
0
bleve/index/store/gouchstore/batch.go
2014-05-19 11:02:15 -04:00

40 lines
862 B
Go

package gouchstore
import (
"github.com/mschoch/gouchstore"
)
type GouchstoreBatch struct {
store *GouchstoreStore
bulk gouchstore.BulkWriter
}
func newGouchstoreBatch(store *GouchstoreStore) *GouchstoreBatch {
rv := GouchstoreBatch{
store: store,
bulk: store.db.Bulk(),
}
return &rv
}
func (gb *GouchstoreBatch) Set(key, val []byte) {
id := string(key)
doc := gouchstore.Document{ID: id, Body: val}
docInfo := gouchstore.DocumentInfo{ID: id, ContentMeta: gouchstore.DOC_IS_COMPRESSED}
gb.bulk.Set(&docInfo, &doc)
}
func (gb *GouchstoreBatch) Delete(key []byte) {
id := string(key)
docInfo := &gouchstore.DocumentInfo{ID: id, ContentMeta: gouchstore.DOC_IS_COMPRESSED}
gb.bulk.Delete(docInfo)
}
func (gb *GouchstoreBatch) Execute() error {
return gb.bulk.Commit()
}
func (gb *GouchstoreBatch) Close() error {
return gb.bulk.Close()
}