func (c *Context) SerializeIndex(index *Index) (err error) { var data []byte var db *bolt.DB if data, err = json.Marshal(index); err != nil { return } db, err = c.OpenDB() if err != nil { return err } defer db.Close() return db.Update(func(tx *bolt.Tx) error { bucket, err := tx.CreateBucketIfNotExists(byteify(IndicesKey)) if err != nil { return err } if bucket == nil { return ErrNoSuchDbBucket } return bucket.Put(byteify(index.FileId), data) }) }
// New creates a wait queue. // The bucket will be created if it does not exist. Otherwise, // the bucket will be deleted and created again. func NewHeap(db *bolt.DB, bucket []byte, bufsize int) (h *Heap, err error) { if err = db.Update(func(tx *bolt.Tx) error { if tx.Bucket(bucket) != nil { if err := tx.DeleteBucket(bucket); err != nil { return err } } if _, err := tx.CreateBucketIfNotExists(bucket); err != nil { return err } return nil }); err != nil { db.Close() return } h = &Heap{ db: db, count: 0, min: nil, writebuf: list.New(), bufsize: bufsize, bucket: bucket, } return }
// tearDownBoltDB closes and deletes boltdb func tearDownBoltDB(db *bolt.DB) error { p := db.Path() err := db.Close() if err != nil { return err } return os.Remove(p) }
// closedb closes and deletes a ReportifyDB database. func closedb(db *bolt.DB) { if db == nil { return } path := db.Path() db.Close() if path != "" { os.Remove(path) } }
func Run(cfg config.Config) (err error) { var db *bolt.DB db, err = bolt.Open(cfg.DatabasePath, 0600, &bolt.Options{Timeout: cfg.Timeout}) if err != nil { return err } defer func() { if err == nil { err = db.Close() } else { db.Close() } }() return nil }
db, err = GetDB(pth) Expect(err).To(BeNil()) u = NewUser( "inspector", UserPassword("abc123bs"), UserPermission("write"), UserDB(db), ) _, err = u.Save() Expect(err).To(BeNil()) }) AfterEach(func() { db.Close() os.RemoveAll(dir) }) It("can save", func() { u2 := NewUser("inspector", UserDB(db)) Expect(u2.Fetch()).To(BeNil()) Expect(u2.Password).To(Equal("")) Expect(len(u2.HashedPassword)).ToNot(Equal(0)) Expect(u2.Permission).To(Equal("write")) }) It("can delete", func() { err := u.Delete() Expect(err).To(BeNil()) u2 := NewUser("inspector", UserDB(db))
func closeAndRemove(db *bolt.DB, filename string) { db.Close() removeFile(filename) }
func closePageDatabase(db *bolt.DB) { if db != nil { db.Close() db = nil } }
func clean_bolt(db *bolt.DB) { db.Close() os.Remove(db.Path()) }
func closeDB(db *bolt.DB) { db.Close() if err := os.Remove(getDBPath()); err != nil { panic(err) } }