Skip to content

Commit ea78d17

Browse files
committed
Return indexes when .schema is run
1 parent 768be79 commit ea78d17

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

litecli/packages/special/dbcommands.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ def show_schema(cur, arg=None, **_):
8686
if cur.description:
8787
headers = [x[0] for x in cur.description]
8888
else:
89-
return [(None, None, None, "")]
90-
91-
return [(None, tables, headers, status)]
89+
return [(None, None, None, "")] + _list_indexes(cur, arg=arg)
9290

91+
return [(None, tables, headers, status)] + _list_indexes(cur, arg=arg)
9392

9493
@special_command(
9594
".databases",
@@ -110,26 +109,19 @@ def list_databases(cur, **_):
110109
return [(None, None, None, "")]
111110

112111

113-
@special_command(
114-
".indexes",
115-
".indexes [tablename]",
116-
"List indexes.",
117-
arg_type=PARSED_QUERY,
118-
case_sensitive=True,
119-
aliases=("\\di",),
120-
)
121-
def list_indexes(cur, arg=None, arg_type=PARSED_QUERY, verbose=False):
112+
# This is private to make sure .schemas special command can call the function to retreive the index
113+
def _list_indexes(cur, arg=None, arg_type=PARSED_QUERY, verbose=False):
122114
if arg:
123115
args = ("{0}%".format(arg),)
124116
query = """
125-
SELECT name FROM sqlite_master
117+
SELECT name, sql FROM sqlite_master
126118
WHERE type = 'index' AND tbl_name LIKE ? AND name NOT LIKE 'sqlite_%'
127119
ORDER BY 1
128120
"""
129121
else:
130122
args = tuple()
131123
query = """
132-
SELECT name FROM sqlite_master
124+
SELECT name, sql FROM sqlite_master
133125
WHERE type = 'index' AND name NOT LIKE 'sqlite_%'
134126
ORDER BY 1
135127
"""
@@ -144,6 +136,17 @@ def list_indexes(cur, arg=None, arg_type=PARSED_QUERY, verbose=False):
144136
return [(None, None, None, "")]
145137
return [(None, indexes, headers, status)]
146138

139+
@special_command(
140+
".indexes",
141+
".indexes [tablename]",
142+
"List indexes.",
143+
arg_type=PARSED_QUERY,
144+
case_sensitive=True,
145+
aliases=("\\di",),
146+
)
147+
def list_indexes(cur, arg=None, arg_type=PARSED_QUERY, verbose=False):
148+
return _list_indexes(cur, arg=arg, arg_type=arg_type, verbose=verbose)
149+
147150

148151
@special_command(
149152
".status",

litecli/packages/special/llm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
except ImportError:
2121
llm = None
2222
cli = None
23+
LLM_CLI_COMMANDS = []
24+
MODELS = {}
2325

2426
from . import export
2527
from .main import parse_special_command

litecli/sqlexecute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class SQLExecute(object):
3838
"""
3939

4040
indexes_query = """
41-
SELECT name
41+
SELECT name, sql
4242
FROM sqlite_master
4343
WHERE type = 'index' AND name NOT LIKE 'sqlite_%'
4444
ORDER BY 1

0 commit comments

Comments
 (0)