Allow BrickRecord insert to force not being defered, as well as overriding its query
This commit is contained in:
parent
b73bd6e99d
commit
a01d38ee7a
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user