aboutsummaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-03-31 11:22:27 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-03-31 11:22:27 -0600
commit8dafb2312b25a02bb79ef6216a5f25ad68d4e159 (patch)
tree3958bda45cef20d248216c0897424356a96cffe7 /example_test.go
parentMerge pull request #102 from benbjohnson/fix-freelist (diff)
downloaddedo-8dafb2312b25a02bb79ef6216a5f25ad68d4e159.tar.gz
dedo-8dafb2312b25a02bb79ef6216a5f25ad68d4e159.tar.xz
Remove DB.Open() and only allow bolt.Open().
Per @tv42's suggestion, this commit removes the ability to reopen an instance of DB. All open calls go through bolt.Open(). Fixes #103.
Diffstat (limited to 'example_test.go')
-rw-r--r--example_test.go27
1 files changed, 9 insertions, 18 deletions
diff --git a/example_test.go b/example_test.go
index c09b86f..eeaecf5 100644
--- a/example_test.go
+++ b/example_test.go
@@ -12,8 +12,7 @@ func init() {
func ExampleDB_Update() {
// Open the database.
- var db DB
- db.Open("/tmp/bolt/db_do.db", 0666)
+ db, _ := Open("/tmp/bolt/db_do.db", 0666)
defer db.Close()
// Execute several commands within a write transaction.
@@ -43,8 +42,7 @@ func ExampleDB_Update() {
func ExampleDB_View() {
// Open the database.
- var db DB
- db.Open("/tmp/bolt/db_with.db", 0666)
+ db, _ := Open("/tmp/bolt/db_with.db", 0666)
defer db.Close()
// Insert data into a bucket.
@@ -68,8 +66,7 @@ func ExampleDB_View() {
func ExampleTx_Put() {
// Open the database.
- var db DB
- db.Open("/tmp/bolt/db_put.db", 0666)
+ db, _ := Open("/tmp/bolt/db_put.db", 0666)
defer db.Close()
// Start a write transaction.
@@ -95,8 +92,7 @@ func ExampleTx_Put() {
func ExampleTx_Delete() {
// Open the database.
- var db DB
- db.Open("/tmp/bolt/db_delete.db", 0666)
+ db, _ := Open("/tmp/bolt/db_delete.db", 0666)
defer db.Close()
// Start a write transaction.
@@ -135,8 +131,7 @@ func ExampleTx_Delete() {
func ExampleTx_ForEach() {
// Open the database.
- var db DB
- db.Open("/tmp/bolt/tx_foreach.db", 0666)
+ db, _ := Open("/tmp/bolt/tx_foreach.db", 0666)
defer db.Close()
// Insert data into a bucket.
@@ -163,8 +158,7 @@ func ExampleTx_ForEach() {
func ExampleBegin_ReadOnly() {
// Open the database.
- var db DB
- db.Open("/tmp/bolt/tx.db", 0666)
+ db, _ := Open("/tmp/bolt/tx.db", 0666)
defer db.Close()
// Create a bucket.
@@ -196,8 +190,7 @@ func ExampleBegin_ReadOnly() {
func ExampleTx_rollback() {
// Open the database.
- var db DB
- db.Open("/tmp/bolt/tx_rollback.db", 0666)
+ db, _ := Open("/tmp/bolt/tx_rollback.db", 0666)
defer db.Close()
// Create a bucket.
@@ -229,8 +222,7 @@ func ExampleTx_rollback() {
func ExampleDB_CopyFile() {
// Open the database.
- var db DB
- db.Open("/tmp/bolt/db_copy.db", 0666)
+ db, _ := Open("/tmp/bolt/db_copy.db", 0666)
defer db.Close()
// Create a bucket and a key.
@@ -244,8 +236,7 @@ func ExampleDB_CopyFile() {
db.CopyFile("/tmp/bolt/db_copy_2.db", 0666)
// Open the cloned database.
- var db2 DB
- db2.Open("/tmp/bolt/db_copy_2.db", 0666)
+ db2, _ := Open("/tmp/bolt/db_copy_2.db", 0666)
defer db2.Close()
// Ensure that the key exists in the copy.