diff --git a/bricktracker/record.py b/bricktracker/record.py index 27f2103..184697d 100644 --- a/bricktracker/record.py +++ b/bricktracker/record.py @@ -1,5 +1,5 @@ from sqlite3 import Row -from typing import Any, ItemsView +from typing import Any, ItemsView, Tuple from .fields import BrickRecordFields from .sql import BrickSQL @@ -24,17 +24,31 @@ class BrickRecord(object): # Insert into the database # If we do not commit immediately, we defer the execute() call - def insert(self, /, *, commit=True) -> None: + def insert( + self, + /, + *, + commit=True, + no_defer=False, + override_query: str | None = None + ) -> Tuple[int, str]: + if override_query: + query = override_query + else: + query = self.insert_query + database = BrickSQL() rows, q = database.execute( - self.insert_query, + query, parameters=self.sql_parameters(), - defer=not commit, + defer=not commit and not no_defer, ) if commit: database.commit() + return rows, q + # Shorthand to field items def items(self, /) -> ItemsView[str, Any]: return self.fields.__dict__.items()