Use more intuitive argument order in sql.delete.

This commit is contained in:
Ryan Roden-Corrent 2017-06-29 20:43:42 -04:00
parent 9c0c174534
commit c007f592b3
4 changed files with 7 additions and 8 deletions

View File

@ -122,8 +122,8 @@ class WebHistory(sql.SqlTable):
Args: Args:
url: URL string to delete. url: URL string to delete.
""" """
self.delete(url, 'url') self.delete('url', url)
self.completion.delete(url, 'url') self.completion.delete('url', url)
@pyqtSlot(QUrl, QUrl, str) @pyqtSlot(QUrl, QUrl, str)
def add_from_tab(self, url, requested_url, title): def add_from_tab(self, url, requested_url, title):

View File

@ -78,7 +78,6 @@ class SqlCategory(QSqlQueryModel):
Args: Args:
pattern: string pattern to filter by. pattern: string pattern to filter by.
columns_to_filter: indices of columns to apply pattern to.
""" """
# escape to treat a user input % or _ as a literal, not a wildcard # escape to treat a user input % or _ as a literal, not a wildcard
pattern = pattern.replace('%', '\\%') pattern = pattern.replace('%', '\\%')

View File

@ -170,12 +170,12 @@ class SqlTable(QObject):
q.run() q.run()
return q.value() return q.value()
def delete(self, value, field): def delete(self, field, value):
"""Remove all rows for which `field` equals `value`. """Remove all rows for which `field` equals `value`.
Args: Args:
value: Key value to delete.
field: Field to use as the key. field: Field to use as the key.
value: Key value to delete.
Return: Return:
The number of rows deleted. The number of rows deleted.

View File

@ -124,12 +124,12 @@ def test_delete(qtbot):
table.insert({'name': 'nine', 'val': 9, 'lucky': False}) table.insert({'name': 'nine', 'val': 9, 'lucky': False})
table.insert({'name': 'thirteen', 'val': 13, 'lucky': True}) table.insert({'name': 'thirteen', 'val': 13, 'lucky': True})
with pytest.raises(KeyError): with pytest.raises(KeyError):
table.delete('nope', 'name') table.delete('name', 'nope')
with qtbot.waitSignal(table.changed): with qtbot.waitSignal(table.changed):
table.delete('thirteen', 'name') table.delete('name', 'thirteen')
assert list(table) == [('one', 1, False), ('nine', 9, False)] assert list(table) == [('one', 1, False), ('nine', 9, False)]
with qtbot.waitSignal(table.changed): with qtbot.waitSignal(table.changed):
table.delete(False, field='lucky') table.delete('lucky', False)
assert not list(table) assert not list(table)