Add parameter ignore_duplicates to insert function.
This commit is contained in:
parent
d9a5d0811d
commit
9385b365cd
1 changed files with 5 additions and 2 deletions
|
@ -433,11 +433,14 @@ class Database(metaclass=abc.ABCMeta):
|
|||
tables = set(self.select_column(query))
|
||||
return tables
|
||||
|
||||
def insert(self, table, pairs) -> sqlite3.Cursor:
|
||||
def insert(self, table, pairs, *, ignore_duplicate=False) -> sqlite3.Cursor:
|
||||
if isinstance(table, type) and issubclass(table, Object):
|
||||
table = table.table
|
||||
self.assert_table_exists(table)
|
||||
(qmarks, bindings) = sqlhelpers.insert_filler(pairs)
|
||||
if ignore_duplicate:
|
||||
query = f'INSERT OR IGNORE INTO {table} {qmarks}'
|
||||
else:
|
||||
query = f'INSERT INTO {table} {qmarks}'
|
||||
return self.execute(query, bindings)
|
||||
|
||||
|
|
Loading…
Reference in a new issue