diff --git a/src/github.com/otoolep/rqlite/db/db.go b/src/github.com/otoolep/rqlite/db/db.go index fd763078..01a5ae27 100644 --- a/src/github.com/otoolep/rqlite/db/db.go +++ b/src/github.com/otoolep/rqlite/db/db.go @@ -3,6 +3,7 @@ package db import ( "database/sql" "errors" + "os" _ "github.com/mattn/go-sqlite3" @@ -26,8 +27,14 @@ type DB struct { type RowResult map[string]string type RowResults []map[string]string -// New creates a new database. +// New creates a new database. Deletes any existing database. func New(dbPath string) *DB { + os.Remove(dbPath) + return Open(dbPath) +} + +// Open an existing database, creating it if it does not exist. +func Open(dbPath string) *DB { log.Trace("SQLite database path is %s", dbPath) dbc, err := sql.Open("sqlite3", dbPath) if err != nil { diff --git a/src/github.com/otoolep/rqlite/db/db_test.go b/src/github.com/otoolep/rqlite/db/db_test.go index 66d86151..cdc3642a 100644 --- a/src/github.com/otoolep/rqlite/db/db_test.go +++ b/src/github.com/otoolep/rqlite/db/db_test.go @@ -203,7 +203,7 @@ func (s *DbSuite) Test_TransactionsHardFail(c *C) { c.Assert(err, IsNil) db.Close() - db = New(path.Join(dir, "test_db")) + db = Open(path.Join(dir, "test_db")) c.Assert(db, NotNil) r, err := db.Query("SELECT * FROM foo") c.Assert(len(r), Equals, 1)