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
This commit is contained in:
parent
fac055c24e
commit
b686bbacf5
1 changed files with 14 additions and 15 deletions
29
doc.go
29
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,
|
import it, setup a database, insert some data into it, and optionally,
|
||||||
query the data back. In a more concrete example:
|
query the data back. In a more concrete example:
|
||||||
|
|
||||||
// Import packages
|
// Import packages.
|
||||||
import (
|
import (
|
||||||
"github.com/conformal/btcdb"
|
"github.com/conformal/btcdb"
|
||||||
_ "github.com/conformal/btcdb/db_sqlite"
|
_ "github.com/conformal/btcdb/sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create a database
|
// Create a database and schedule it to be closed on exit.
|
||||||
dbname := "dbexample"
|
dbName := "example.db"
|
||||||
db, err := btcdb.CreateDB("sqlite", dbname)
|
db, err := btcdb.CreateDB("sqlite", dbName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to open database %v", err)
|
// Log and handle the error
|
||||||
return
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
// Insert a block.
|
||||||
|
newHeight, err := db.InsertBlock(block)
|
||||||
|
if err != nil {
|
||||||
|
// Log and handle the error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert a block
|
// Sync the database.
|
||||||
newheight, err := db.InsertBlock(block)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("failed to insert block %v err %v", height, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sync the database
|
|
||||||
db.Sync()
|
db.Sync()
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package btcdb
|
package btcdb
|
||||||
|
|
Loading…
Reference in a new issue