Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dot command for views #217

Merged
merged 1 commit into from
Mar 11, 2025
Merged

Conversation

zachvalenta
Copy link
Contributor

Description

I use the .tables command a lot and occurred to me it might be useful to have one for views as well. I'd use it at least!

Checklist

  • I've added this contribution to the CHANGELOG.md file.

@zachvalenta
Copy link
Contributor Author

@amjith It occurs to me - if the premise of this PR is accepted - there's likely some doc changes that need to be made. Happy to chip in there as well, just lemme know.

@amjith
Copy link
Member

amjith commented Feb 28, 2025

Could you add a test for this? Here's a good candidate test you can use as reference.
https://github.com/dbcli/litecli/blob/main/tests/test_dbspecial.py#L94-L99

@amjith
Copy link
Member

amjith commented Feb 28, 2025

BTW, I like the PR I do plan on merging this once I get a chance to try it out locally.

@zachvalenta
Copy link
Contributor Author

Sounds good on both counts! Will do it over the weekend if that works.

@kracekumar
Copy link
Contributor

I tried the branch in my local db and works as expected. Here is the output

 uv run litecli /Users/kracekumar/Downloads/github.db
LiteCli: 0.1.dev429+g5be771e (SQLite: 3.47.1)
GitHub: https://github.com/dbcli/litecli
/Users/kracekumar/Downloads/github.db> .views
+-----------------+
| name            |
+-----------------+
| dependent_repos |
| recent_releases |
| repos_starred   |
+-----------------+
Time: 0.010s
/Users/kracekumar/Downloads/github.db> \dv
+-----------------+
| name            |
+-----------------+
| dependent_repos |
| recent_releases |
| repos_starred   |
+-----------------+
Time: 0.005s
/Users/kracekumar/Downloads/github.db> SELECT name
                                       FROM sqlite_schema
                                       WHERE type = 'view';
+-----------------+
| name            |
+-----------------+
| dependent_repos |
| recent_releases |
| repos_starred   |
+-----------------+
3 rows in set
Time: 0.004s
/Users/kracekumar/Downloads/github.db> SELECT name
                                       FROM sqlite_master
                                       WHERE type = 'view';
+-----------------+
| name            |
+-----------------+
| dependent_repos |
| recent_releases |
| repos_starred   |
+-----------------+
3 rows in set
Time: 0.004s
/Users/kracekumar/Downloads/github.db> .views repos_starred
+---------------+
| name          |
+---------------+
| repos_starred |
+---------------+
Time: 0.006s
/Users/kracekumar/Downloads/github.db>







 [F3] Multiline: OFF

Database Source: https://github-to-sqlite.dogsheep.net/github

args = tuple()
query = """
SELECT name FROM sqlite_master
WHERE type = 'view' AND name NOT LIKE 'sqlite_%'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason to ignore views with prefix sqlite_? Do you happen to know when these(sqlite_xxx) views are created?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this query is a modified version of the tables_query in sqlexecute.py. SQLite will create temporary tables for query planning purposes such as sqlite_stat*. I don't think it is applicable to views.

@amjith
Copy link
Member

amjith commented Mar 11, 2025

Merging this now. I can add tests for it.

@amjith amjith merged commit 62f5adf into dbcli:main Mar 11, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants