diff --git a/cmd/genji/shell/shell.go b/cmd/genji/shell/shell.go index bf0e2dcee..e02eff8c8 100644 --- a/cmd/genji/shell/shell.go +++ b/cmd/genji/shell/shell.go @@ -314,6 +314,33 @@ func (sh *Shell) changelivePrefix() (string, bool) { return sh.livePrefix, sh.multiLine } +func (sh *Shell) getAllIndexes() ([]string, error) { + db, err := sh.getDB() + if err != nil { + return nil, err + } + + var listName []string + err = db.View(func(tx *genji.Tx) error { + indexes, err := tx.ListIndexes() + if err != nil { + return err + } + + for _, idx := range indexes { + listName = append(listName, idx.IndexName) + } + + return nil + }) + + if len(listName) == 0 { + listName = append(listName, "index_name") + } + + return listName, err +} + // getTables returns all the tables of the database func (sh *Shell) getAllTables() ([]string, error) { var tables []string @@ -356,6 +383,11 @@ func (sh *Shell) completer(in prompt.Document) []prompt.Suggest { if err != nil { return []prompt.Suggest{} } + case "index_name": + expected, err = sh.getAllIndexes() + if err != nil { + return []prompt.Suggest{} + } } suggestions := make([]prompt.Suggest, len(expected)) diff --git a/sql/parser/drop.go b/sql/parser/drop.go index 086be9005..e1f0c1c3a 100644 --- a/sql/parser/drop.go +++ b/sql/parser/drop.go @@ -67,7 +67,9 @@ func (p *Parser) parseDropIndexStatement() (query.DropIndexStmt, error) { // Parse index name stmt.IndexName, err = p.parseIdent() if err != nil { - return stmt, err + pErr := err.(*ParseError) + pErr.Expected = []string{"index_name"} + return stmt, pErr } return stmt, nil