mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
Support overriding the database file.
This commit is contained in:
parent
f454cfb386
commit
56490fcd31
7
main.go
7
main.go
|
@ -39,6 +39,7 @@ func usage() {
|
|||
|
||||
var (
|
||||
debuglog = flag.String("debuglog", "", "a file to write debug log to")
|
||||
dbname = flag.String("db", "", "path to the database")
|
||||
help = flag.Bool("help", false, "show usage help and quit")
|
||||
)
|
||||
|
||||
|
@ -212,7 +213,11 @@ func newEvalerAndStore() (*eval.Evaler, *store.Store) {
|
|||
|
||||
var st *store.Store
|
||||
if err == nil {
|
||||
st, err = store.NewStore(dataDir)
|
||||
db := *dbname
|
||||
if db == "" {
|
||||
db = dataDir + "/db"
|
||||
}
|
||||
st, err = store.NewStore(db)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Warning: cannot connect to store:", err)
|
||||
}
|
||||
|
|
|
@ -17,15 +17,15 @@ type Store struct {
|
|||
var initTable = map[string](func(*sql.DB) error){}
|
||||
|
||||
// DefaultDB returns the default database for storage.
|
||||
func DefaultDB(dataDir string) (*sql.DB, error) {
|
||||
uri := "file:" + url.QueryEscape(dataDir+"/db") +
|
||||
func DefaultDB(dbname string) (*sql.DB, error) {
|
||||
uri := "file:" + url.QueryEscape(dbname) +
|
||||
"?mode=rwc&cache=shared&vfs=unix-dotfile"
|
||||
return sql.Open("sqlite3", uri)
|
||||
}
|
||||
|
||||
// NewStore creates a new Store with the default database.
|
||||
func NewStore(dataDir string) (*Store, error) {
|
||||
db, err := DefaultDB(dataDir)
|
||||
func NewStore(dbname string) (*Store, error) {
|
||||
db, err := DefaultDB(dbname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user