From b686bbacf58b21c05ea6b733be3bd87caa695e71 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 31 May 2013 13:50:23 -0500 Subject: [PATCH] Update and fix usage example. This commit updates the usage example as follows: - Add a defer db.Close since the database should be closed after the caller is done with it - Correct the import path for the btcdb/sqlite3 package - Add a db extension to the example database name - Make the error handling and comments match the standard style --- doc.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/doc.go b/doc.go index dc96fbf0..a93131fc 100644 --- a/doc.go +++ b/doc.go @@ -29,28 +29,27 @@ At the highest level, the use of this packages just requires that you import it, setup a database, insert some data into it, and optionally, query the data back. In a more concrete example: - // Import packages + // Import packages. import ( "github.com/conformal/btcdb" - _ "github.com/conformal/btcdb/db_sqlite" + _ "github.com/conformal/btcdb/sqlite3" ) - // Create a database - dbname := "dbexample" - db, err := btcdb.CreateDB("sqlite", dbname) + // Create a database and schedule it to be closed on exit. + dbName := "example.db" + db, err := btcdb.CreateDB("sqlite", dbName) if err != nil { - fmt.Printf("Failed to open database %v", err) - return + // Log and handle the error + } + defer db.Close() + + // Insert a block. + newHeight, err := db.InsertBlock(block) + if err != nil { + // Log and handle the error } - // Insert a block - newheight, err := db.InsertBlock(block) - if err != nil { - fmt.Printf("failed to insert block %v err %v", height, err) - } - - // Sync the database + // Sync the database. db.Sync() - */ package btcdb