store: createTable -> initTable

This commit is contained in:
Qi Xiao 2016-02-12 21:37:14 +01:00
parent c6bcb714c1
commit 2468aece8d
3 changed files with 5 additions and 5 deletions

View File

@ -10,7 +10,7 @@ import (
var ErrNoMatchingCmd = errors.New("no matching command line")
func init() {
createTable["cmd"] = `create table if not exists cmd (content text)`
initTable["cmd"] = `create table if not exists cmd (content text)`
}
// NextCmdSeq returns the next sequence number of the command history.

View File

@ -13,7 +13,7 @@ const (
)
func init() {
createTable["dir"] = `create table if not exists dir (path text unique primary key, score real default 0)`
initTable["dir"] = `create table if not exists dir (path text unique primary key, score real default 0)`
}
// AddDir adds a directory to the directory history.

View File

@ -14,7 +14,7 @@ type Store struct {
db *sql.DB
}
var createTable = map[string]string{}
var initTable = map[string]string{}
// DefaultDB returns the default database for storage.
func DefaultDB(dataDir string) (*sql.DB, error) {
@ -37,10 +37,10 @@ func NewStore(dataDir string) (*Store, error) {
func NewStoreDB(db *sql.DB) (*Store, error) {
st := &Store{db}
for t, q := range createTable {
for t, q := range initTable {
_, err := db.Exec(q)
if err != nil {
return nil, fmt.Errorf("failed to create table %s: %v", t, q)
return nil, fmt.Errorf("failed to initialize table %s: %v", t, q)
}
}