From a01d38ee7a57b762cca3027df27ef34e31ada74f Mon Sep 17 00:00:00 2001 From: Gregoo Date: Fri, 24 Jan 2025 10:11:15 +0100 Subject: [PATCH] Allow BrickRecord insert to force not being defered, as well as overriding its query --- bricktracker/record.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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()