forked from ZhengHe-MD/learn-bolt
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhenghe3119
committed
Aug 8, 2019
1 parent
1571866
commit 93454c2
Showing
4 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/boltdb/bolt" | ||
"log" | ||
) | ||
|
||
func main() { | ||
db, err := bolt.Open("1.db", 0600, nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer db.Close() | ||
|
||
err = db.Update(func(tx *bolt.Tx) error { | ||
b1, err := tx.CreateBucketIfNotExists([]byte("b1")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = b1.CreateBucketIfNotExists([]byte("b11")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_ = b1.Put([]byte("k1"), []byte("v1")) | ||
_ = b1.Put([]byte("k2"), []byte("v2")) | ||
|
||
return b1.ForEach(func(k, v []byte) error { | ||
fmt.Println(string(k), string(v)) | ||
return nil | ||
}) | ||
}) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/ZhengHe-MD/learn-bolt/api/lib" | ||
"github.com/boltdb/bolt" | ||
"log" | ||
) | ||
|
||
func main() { | ||
db, _ := bolt.Open("mm1.db", 0600, nil) | ||
defer db.Close() | ||
|
||
store := lib.NewStore(db) | ||
|
||
for i := 5000; i < 8000; i++ { | ||
if err := store.Users.DeleteUserByID(uint64(i)); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/ZhengHe-MD/learn-bolt/api/lib" | ||
"github.com/boltdb/bolt" | ||
"log" | ||
) | ||
|
||
func main() { | ||
db, _ := bolt.Open("mm1.db", 0600, nil) | ||
defer db.Close() | ||
|
||
store := lib.NewStore(db) | ||
|
||
_ = store.CleanupBuckets() | ||
_ = store.EnsureBuckets() | ||
|
||
n := 10000 | ||
if err := store.GenerateFakeUserDataConcurrently(n, 16); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |