Skip to content

Support completion for sqlite3 command-line interface #133390

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

Open
tanloong opened this issue May 4, 2025 · 7 comments
Open

Support completion for sqlite3 command-line interface #133390

tanloong opened this issue May 4, 2025 · 7 comments
Labels
stdlib Python modules in the Lib dir topic-sqlite3 type-feature A feature request or enhancement

Comments

@tanloong
Copy link
Contributor

tanloong commented May 4, 2025

Feature or enhancement

Proposal:

Current sqlite3 CLI lacks tab-completion feature. Hope it can be supported to improve usability.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@tanloong tanloong added the type-feature A feature request or enhancement label May 4, 2025
@StanFromIreland
Copy link
Contributor

This is a minor feature

I would disagree, this would presumably require quite a lot of work to implement and then maintain. Maybe this should be discussion on discourse first?

@tanloong
Copy link
Contributor Author

tanloong commented May 4, 2025

Right. But I think for the moment we can support basic completion which takes not much work but gives big experience enhancement.

@picnixz picnixz added extension-modules C modules in the Modules dir stdlib Python modules in the Lib dir and removed extension-modules C modules in the Modules dir labels May 4, 2025
@StanFromIreland
Copy link
Contributor

#133393 introduces keyword expansion, but what about name expansion (the part I was originally worried about)?

@tanloong
Copy link
Contributor Author

tanloong commented May 4, 2025

Can we get the name list when connecting to a disk-file database, merge it with keyword list as completion candidates? Also the name list need to be updated on deletion/creation of table/column.

import sqlite3

def get_names(db_path):
    ret = []
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()

    cursor.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;")
    tables = [row[0] for row in cursor.fetchall()] # get table names
    ret.extend(tables)

    for table in tables:
        cursor.execute(f"PRAGMA table_info({table})")
        ret.extend(row[1] for row in cursor.fetchall()) # get column names

    conn.close()
    return ret

db_path = '/path/to/db.db'
list_of_names = get_names(db_path)

@StanFromIreland
Copy link
Contributor

StanFromIreland commented May 5, 2025

@hugovk (BDFC ;-) out of curiosity, is this on your list for colorising, it is a good candidate ? I’d take a stab at it once this is merged.

@hugovk
Copy link
Member

hugovk commented May 5, 2025

It's not on my list but sounds like a good candidate. See also #133247 that added syntax highlighting in the REPL and tools like https://github.com/dbcli/litecli.

@StanFromIreland
Copy link
Contributor

sounds like a good candidate.

Opened #133447 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-sqlite3 type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants