How-boltdb-Write-its-Data

How boltdb Write its Data? A-Ha!Here’re three questions during reading the source code of BoltDB. I’ll explain our testing procedure to dive into the core of the BoltDB writing mechanism. Code link: yhyddr/quicksilver FirstAt first, my mentor posts a question: “Did BoltDB have a temporary file when starting a read/write transaction”. Following the quickstart, all data is stored in a file on disk. Generally speaking, the file has a linerial structure, when inserting, updating and deleting, we have to re-arrange the space occupied by this file. A tempory file should be used in this procedure, for example, .swp file for VIM. ...

October 9, 2019 · 4 min · jiezi

boltdb-基础使用

https://www.yuque.com/abs/dr4... Using Store ???? Using Buckets桶是键值对的集合。在一个桶中,键值唯一。 创建使用 Tx.CreateBucket() 和 Tx.CreateBucketIfNotExists() 建立一个新桶(推荐使用第二个)接受参数是 桶的名字 删除使用 Tx.DeleteBucket() 根据桶的名字来删除 例子func main() { db, err := bbolt.Open("./data", 0666, nil) if err != nil { log.Fatal(err) } defer db.Close() db.Update(func(tx *bbolt.Tx) error { b, err := tx.CreateBucketIfNotExists([]byte("MyBucket")) if err != nil { return fmt.Errorf("create bucket: %v", err) } if err = tx.DeleteBucket([]byte("MyBucket")); err != nil { return err } return nil })} ...

October 2, 2019 · 2 min · jiezi