You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reader.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2014 Couchbase, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package boltdb
  15. import (
  16. "github.com/blevesearch/bleve/index/store"
  17. bolt "go.etcd.io/bbolt"
  18. )
  19. type Reader struct {
  20. store *Store
  21. tx *bolt.Tx
  22. bucket *bolt.Bucket
  23. }
  24. func (r *Reader) Get(key []byte) ([]byte, error) {
  25. var rv []byte
  26. v := r.bucket.Get(key)
  27. if v != nil {
  28. rv = make([]byte, len(v))
  29. copy(rv, v)
  30. }
  31. return rv, nil
  32. }
  33. func (r *Reader) MultiGet(keys [][]byte) ([][]byte, error) {
  34. return store.MultiGet(r, keys)
  35. }
  36. func (r *Reader) PrefixIterator(prefix []byte) store.KVIterator {
  37. cursor := r.bucket.Cursor()
  38. rv := &Iterator{
  39. store: r.store,
  40. tx: r.tx,
  41. cursor: cursor,
  42. prefix: prefix,
  43. }
  44. rv.Seek(prefix)
  45. return rv
  46. }
  47. func (r *Reader) RangeIterator(start, end []byte) store.KVIterator {
  48. cursor := r.bucket.Cursor()
  49. rv := &Iterator{
  50. store: r.store,
  51. tx: r.tx,
  52. cursor: cursor,
  53. start: start,
  54. end: end,
  55. }
  56. rv.Seek(start)
  57. return rv
  58. }
  59. func (r *Reader) Close() error {
  60. return r.tx.Rollback()
  61. }