diff --git a/boltrest.go b/boltrest.go index 66eae5c..225a70d 100644 --- a/boltrest.go +++ b/boltrest.go @@ -23,22 +23,36 @@ type DB struct { apiToken string remoteMD5 string online bool + isOpen bool localDB *bolt.DB } -// Open returns the DB object -func Open(filename string) (*DB, error) { +// Create returns the DB object +func Create(filename string) (*DB, error) { var err error b := DB{localFile: filename} b.localDB, err = bolt.Open(filename, 0644, nil) if err != nil { return nil, err } + defer b.localDB.Close() // Go ahead and make sure it's fresh b.RefreshDB() return &b, nil } +// Open opens the DB so things can be done +func (b *DB) Open() error { + var err error + b.localDB, err = Open(b.localFile, 0644, nil) + return err +} + +// Close closes the DB +func (b *DB) Close() error { + return b.localDB.Close() +} + // Offline sets this DB to offline mode // That means it won't try to sync anything func (b *DB) Offline() {