Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support document type #333

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions tinydb/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ def perform_update(table, doc_id):
# Update documents by setting all fields from the provided data
table[doc_id].update(fields)

if cond is None and doc_ids is None and isinstance(fields, Document):
doc_ids = [fields.doc_id]

if doc_ids is not None:
# Perform the update operation for documents specified by a list
# of document IDs
Expand Down Expand Up @@ -413,19 +416,23 @@ def upsert(self, document: Mapping, cond: Query) -> List[int]:

def remove(
self,
cond: Optional[Query] = None,
cond: Optional[Union[Document, Query]] = None,
doc_ids: Optional[Iterable[int]] = None,
) -> List[int]:
"""
Remove all matching documents.

:param cond: the condition to check against
:param cond: the condition to check against, or the document to remove
:param doc_ids: a list of document IDs
:returns: a list containing the removed documents' ID
"""
if cond is None and doc_ids is None:
raise RuntimeError('Use truncate() to remove all documents')

if doc_ids is None and isinstance(cond, Document):
doc_ids = [cond.doc_id]
cond = None

if cond is not None:
removed_ids = []

Expand Down