mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-24 18:04:32 +02:00
Ability to add descending order indexes (#262)
* DescIndex(column) for descending index columns, refs #260 * Ability to add desc indexes using CLI, closes #260
This commit is contained in:
parent
b2302875c9
commit
51d01da30d
6 changed files with 69 additions and 4 deletions
|
|
@ -1033,6 +1033,14 @@ Use the ``--unique`` option to create a unique index.
|
|||
|
||||
Use ``--if-not-exists`` to avoid attempting to create the index if one with that name already exists.
|
||||
|
||||
To add an index on a column in descending order, prefix the column with a hyphen. Since this can be confused for a command-line option you need to construct that like this::
|
||||
|
||||
$ sqlite-utils create-index mydb.db mytable -- col1 -col2 col3
|
||||
|
||||
This will create an index on that table on ``(col1, col2 desc, col3)``.
|
||||
|
||||
If your column names are already prefixed with a hyphen you'll need to manually execute a ``CREATE INDEX`` SQL statement to add indexes to them rather than using this tool.
|
||||
|
||||
.. _cli_fts:
|
||||
|
||||
Configuring full-text search
|
||||
|
|
|
|||
|
|
@ -1866,6 +1866,17 @@ By default the index will be named ``idx_{table-name}_{columns}`` - if you want
|
|||
index_name="good_dogs_by_age"
|
||||
)
|
||||
|
||||
To create an index in descending order for a column, wrap the column name in ``db.DescIndex()`` like this:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from sqlite_utils.db import DescIndex
|
||||
|
||||
db["dogs"].create_index(
|
||||
["is_good_dog", DescIndex("age")],
|
||||
index_name="good_dogs_by_age"
|
||||
)
|
||||
|
||||
You can create a unique index by passing ``unique=True``:
|
||||
|
||||
.. code-block:: python
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue