Skip to content

sqlite-utils indexes command #263

Description

@simonw

While working on #260 I realized there's no command to show indexes in a database, even though there is one for showing tables and one for triggers.

I should implement #261 first.

Activity

  1. simonw commented on Jun 3, 2021

    @simonw
    OwnerAuthor

    Here's how sqlite-utils triggers works:

    ):
    "Show triggers configured in this database"
    sql = "select name, tbl_name as [table], sql from sqlite_master where type = 'trigger'"
    if tables:
    quote = sqlite_utils.Database(memory=True).quote
    sql += " and [table] in ({})".format(
    ", ".join(quote(table) for table in tables)
    )
    ctx.invoke(
    query,
    path=path,
    sql=sql,

    Running it from a SQL query makes it easy to support modifiers like --csv and -t.

  2. simonw commented on Jun 3, 2021

    @simonw
    OwnerAuthor
  3. simonw commented on Jun 3, 2021

    @simonw
    OwnerAuthor

    By default I won't return auxiliary columns, but I'll offer a --aux option to return them.

  4. simonw commented on Jun 3, 2021

    @simonw
    OwnerAuthor

    This looks good:

    % sqlite-utils indexes /tmp/covid.db -t      
    index_name                                                seqno    cid  name                 desc  coll      key
    ------------------------------------------------------  -------  -----  -----------------  ------  ------  -----
    idx_johns_hopkins_csse_daily_reports_combined_key             0     12  combined_key            0  BINARY      1
    idx_johns_hopkins_csse_daily_reports_country_or_region        0      1  country_or_region       0  BINARY      1
    idx_johns_hopkins_csse_daily_reports_province_or_state        0      2  province_or_state       0  BINARY      1
    idx_johns_hopkins_csse_daily_reports_day                      0      0  day                     0  BINARY      1
    idx_ny_times_us_counties_date                                 0      0  date                    1  BINARY      1
    idx_ny_times_us_counties_fips                                 0      3  fips                    0  BINARY      1
    idx_ny_times_us_counties_county                               0      1  county                  0  BINARY      1
    idx_ny_times_us_counties_state                                0      2  state                   0  BINARY      1
    
    % sqlite-utils indexes /tmp/covid.db -t --aux
    index_name                                                seqno    cid  name                 desc  coll      key
    ------------------------------------------------------  -------  -----  -----------------  ------  ------  -----
    idx_johns_hopkins_csse_daily_reports_combined_key             0     12  combined_key            0  BINARY      1
    idx_johns_hopkins_csse_daily_reports_combined_key             1     -1                          0  BINARY      0
    idx_johns_hopkins_csse_daily_reports_country_or_region        0      1  country_or_region       0  BINARY      1
    idx_johns_hopkins_csse_daily_reports_country_or_region        1     -1                          0  BINARY      0
    idx_johns_hopkins_csse_daily_reports_province_or_state        0      2  province_or_state       0  BINARY      1
    idx_johns_hopkins_csse_daily_reports_province_or_state        1     -1                          0  BINARY      0
    idx_johns_hopkins_csse_daily_reports_day                      0      0  day                     0  BINARY      1
    idx_johns_hopkins_csse_daily_reports_day                      1     -1                          0  BINARY      0
    idx_ny_times_us_counties_date                                 0      0  date                    1  BINARY      1
    idx_ny_times_us_counties_date                                 1     -1                          0  BINARY      0
    idx_ny_times_us_counties_fips                                 0      3  fips                    0  BINARY      1
    idx_ny_times_us_counties_fips                                 1     -1                          0  BINARY      0
    idx_ny_times_us_counties_county                               0      1  county                  0  BINARY      1
    idx_ny_times_us_counties_county                               1     -1                          0  BINARY      0
    idx_ny_times_us_counties_state                                0      2  state                   0  BINARY      1
    idx_ny_times_us_counties_state                                1     -1                          0  BINARY      0
    
  5. simonw commented on Jun 3, 2021

    @simonw
    OwnerAuthor

    Needs to show the table each index applies to.

  6. simonw commented on Jun 3, 2021

    @simonw
    OwnerAuthor
  7. added a commit that references this issue on Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions