From 9385b365cdec2403170776e3a80995bf450285d9 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 24 Mar 2025 22:15:43 -0700 Subject: [PATCH] Add parameter ignore_duplicates to insert function. --- voussoirkit/worms.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index 31457bd..e618499 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -433,12 +433,15 @@ 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) - query = f'INSERT INTO {table} {qmarks}' + if ignore_duplicate: + query = f'INSERT OR IGNORE INTO {table} {qmarks}' + else: + query = f'INSERT INTO {table} {qmarks}' return self.execute(query, bindings) def normalize_object_id(self, object_class, object_id):