diff options
Diffstat (limited to 'litecli/packages')
-rw-r--r-- | litecli/packages/completion_engine.py | 4 | ||||
-rw-r--r-- | litecli/packages/special/dbcommands.py | 53 |
2 files changed, 37 insertions, 20 deletions
diff --git a/litecli/packages/completion_engine.py b/litecli/packages/completion_engine.py index 0397857..0e2a30f 100644 --- a/litecli/packages/completion_engine.py +++ b/litecli/packages/completion_engine.py @@ -105,14 +105,14 @@ def suggest_special(text): if cmd in ["\\f", "\\fs", "\\fd"]: return [{"type": "favoritequery"}] - if cmd in ["\\d", "\\dt", "\\dt+", ".schema"]: + if cmd in ["\\d", "\\dt", "\\dt+", ".schema", ".indexes"]: return [ {"type": "table", "schema": []}, {"type": "view", "schema": []}, {"type": "schema"}, ] - if cmd in ["\\.", "source", ".open"]: + if cmd in ["\\.", "source", ".open", ".read"]: return [{"type": "file_name"}] if cmd in [".import"]: diff --git a/litecli/packages/special/dbcommands.py b/litecli/packages/special/dbcommands.py index a7eaa0c..203e1a8 100644 --- a/litecli/packages/special/dbcommands.py +++ b/litecli/packages/special/dbcommands.py @@ -111,6 +111,41 @@ def list_databases(cur, **_): @special_command( + ".indexes", + ".indexes [tablename]", + "List indexes.", + arg_type=PARSED_QUERY, + case_sensitive=True, + aliases=("\\di",), +) +def list_indexes(cur, arg=None, arg_type=PARSED_QUERY, verbose=False): + if arg: + args = ("{0}%".format(arg),) + query = """ + SELECT name FROM sqlite_master + WHERE type = 'index' AND tbl_name LIKE ? AND name NOT LIKE 'sqlite_%' + ORDER BY 1 + """ + else: + args = tuple() + query = """ + SELECT name FROM sqlite_master + WHERE type = 'index' AND name NOT LIKE 'sqlite_%' + ORDER BY 1 + """ + + log.debug(query) + cur.execute(query, args) + indexes = cur.fetchall() + status = "" + if cur.description: + headers = [x[0] for x in cur.description] + else: + return [(None, None, None, "")] + return [(None, indexes, headers, status)] + + +@special_command( ".status", "\\s", "Show current settings.", @@ -203,24 +238,6 @@ def describe(cur, arg, **_): @special_command( - ".read", - ".read path", - "Read input from path", - arg_type=PARSED_QUERY, - case_sensitive=True, -) -def read_script(cur, arg, **_): - args = shlex.split(arg) - if len(args) != 1: - raise TypeError(".read accepts exactly one path") - path = args[0] - with open(path, "r") as f: - script = f.read() - cur.executescript(script) - return [(None, None, None, "")] - - -@special_command( ".import", ".import filename table", "Import data from filename into an existing table", |