mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
order= is now order_by=, refs #197
This commit is contained in:
parent
2bc1e9c5b4
commit
bce1872109
3 changed files with 15 additions and 8 deletions
|
|
@ -1033,7 +1033,7 @@ def search(
|
|||
raise click.ClickException(
|
||||
"Table '{}' has no column '{}".format(dbtable, c)
|
||||
)
|
||||
sql = table_obj.search_sql(columns=column, order=order, limit=limit)
|
||||
sql = table_obj.search_sql(columns=column, order_by=order, limit=limit)
|
||||
if show_sql:
|
||||
click.echo(sql)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1321,7 +1321,7 @@ class Table(Queryable):
|
|||
)
|
||||
return self
|
||||
|
||||
def search_sql(self, columns=None, order=None, limit=None):
|
||||
def search_sql(self, columns=None, order_by=None, limit=None):
|
||||
# Pick names for table and rank column that don't clash
|
||||
original = "original_" if self.name == "original" else "original"
|
||||
rank = "rank"
|
||||
|
|
@ -1352,7 +1352,7 @@ class Table(Queryable):
|
|||
where
|
||||
[{fts_table}] match :query
|
||||
order by
|
||||
{order}
|
||||
{order_by}
|
||||
{limit}
|
||||
"""
|
||||
).strip()
|
||||
|
|
@ -1370,12 +1370,19 @@ class Table(Queryable):
|
|||
rank=rank,
|
||||
rank_implementation=rank_implementation,
|
||||
fts_table=fts_table,
|
||||
order=order or rank,
|
||||
order_by=order_by or rank,
|
||||
limit="limit {}".format(limit) if limit else "",
|
||||
).strip()
|
||||
|
||||
def search(self, q, order=None):
|
||||
cursor = self.db.execute(self.search_sql(order=order), {"query": q})
|
||||
def search(self, q, order_by=None, columns=None, limit=None):
|
||||
cursor = self.db.execute(
|
||||
self.search_sql(
|
||||
order_by=order_by,
|
||||
columns=columns,
|
||||
limit=limit,
|
||||
),
|
||||
{"query": q},
|
||||
)
|
||||
columns = [c[0] for c in cursor.description]
|
||||
for row in cursor:
|
||||
yield dict(zip(columns, row))
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ def test_fts_tokenize(fresh_db):
|
|||
fts_version="FTS{}".format(fts_version),
|
||||
tokenize="porter",
|
||||
)
|
||||
rows = list(table.search("bite", order="rowid"))
|
||||
rows = list(table.search("bite", order_by="rowid"))
|
||||
assert len(rows) == 1
|
||||
assert {
|
||||
"rowid": 2,
|
||||
|
|
@ -391,7 +391,7 @@ def test_enable_fts_replace_does_nothing_if_args_the_same():
|
|||
),
|
||||
),
|
||||
(
|
||||
{"columns": ["title"], "order": "rowid", "limit": 10},
|
||||
{"columns": ["title"], "order_by": "rowid", "limit": 10},
|
||||
"FTS5",
|
||||
(
|
||||
"with original as (\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue