Skip to content

Commit 62f5adf

Browse files
authored
Merge pull request #217 from zachvalenta/add-dot-command-for-views
add dot command for views
2 parents 768be79 + df1dbbd commit 62f5adf

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Add logs while invoking `\llm`and `\\m+` command. [(#215)](https://github.com/dbcli/litecli/pull/215)
66
* Support `--help` in the `\llm`and `\llm+` command. ([#214](https://github.com/dbcli/litecli/pull/214))
77
* Make the history file location configurable. ([#206](https://github.com/dbcli/litecli/issues/206))
8+
* Add dot command to list views.
89

910
### Bug Fixes
1011

litecli/packages/special/dbcommands.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,40 @@ def list_tables(cur, arg=None, arg_type=PARSED_QUERY, verbose=False):
5656
return [(None, tables, headers, status)]
5757

5858

59+
@special_command(
60+
".views",
61+
"\\dv",
62+
"List views.",
63+
arg_type=PARSED_QUERY,
64+
case_sensitive=True,
65+
aliases=("\\dv",),
66+
)
67+
def list_views(cur, arg=None, arg_type=PARSED_QUERY, verbose=False):
68+
if arg:
69+
args = ("{0}%".format(arg),)
70+
query = """
71+
SELECT name FROM sqlite_master
72+
WHERE type = 'view' AND name LIKE ? AND name NOT LIKE 'sqlite_%'
73+
ORDER BY 1
74+
"""
75+
else:
76+
args = tuple()
77+
query = """
78+
SELECT name FROM sqlite_master
79+
WHERE type = 'view' AND name NOT LIKE 'sqlite_%'
80+
ORDER BY 1
81+
"""
82+
log.debug(query)
83+
cur.execute(query, args)
84+
views = cur.fetchall()
85+
status = ""
86+
if cur.description:
87+
headers = [x[0] for x in cur.description]
88+
else:
89+
return [(None, None, None, "")]
90+
return [(None, views, headers, status)]
91+
92+
5993
@special_command(
6094
".schema",
6195
".schema[+] [table]",

0 commit comments

Comments
 (0)