Skip to content

Commit 680fcde

Browse files
authored
Deletion of multiple records (#172)
* Deletion of multiple records * PR comments
1 parent 5c4f482 commit 680fcde

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

business_objects/comments.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from . import general, organization
55
from .. import enums
66
from ..session import session
7-
from typing import Dict, List, Any, Optional, Union
7+
from typing import Dict, List, Any, Optional, Union, Iterable
88
from ..util import prevent_sql_injection
99

1010

@@ -305,6 +305,21 @@ def remove(comment_id: str, with_commit: bool = False) -> None:
305305
general.flush_or_commit(with_commit)
306306

307307

308+
def delete_by_type_and_xfkey(
309+
project_id: str,
310+
xfkeys: Iterable[str],
311+
xftype: enums.CommentCategory,
312+
with_commit: bool = False,
313+
) -> None:
314+
315+
session.query(CommentData).filter(
316+
CommentData.project_id == project_id,
317+
CommentData.xfkey.in_(xfkeys),
318+
CommentData.xftype == xftype.value,
319+
).delete()
320+
general.flush_or_commit(with_commit)
321+
322+
308323
def get_unique_comments_keys_for(
309324
xftype: enums.CommentCategory, project_id: Optional[str] = None
310325
) -> List[str]:

business_objects/record.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,18 @@ def delete(project_id: str, record_id: str, with_commit: bool = False) -> None:
773773
general.flush_or_commit(with_commit)
774774

775775

776+
def delete_many(
777+
project_id: str, record_ids: Iterable[str], with_commit: bool = False
778+
) -> int:
779+
res = (
780+
session.query(Record)
781+
.filter(Record.project_id == project_id, Record.id.in_(record_ids))
782+
.delete()
783+
)
784+
general.flush_or_commit(with_commit)
785+
return res
786+
787+
776788
def delete_all(project_id: str, with_commit: bool = False) -> None:
777789
session.query(Record).filter(Record.project_id == project_id).delete()
778790
general.flush_or_commit(with_commit)

0 commit comments

Comments
 (0)