neosqlite.collection.query_helper.crud_operations module

CRUD operations for QueryHelper.

class neosqlite.collection.query_helper.crud_operations.CRUDOperationsMixin[source]

Bases: object

Mixin providing CRUD operations for QueryHelper.

collection: Collection
_get_integer_id_for_oid: Any
_validate_json_document: Any
_get_json_error_position: Any
_internal_insert(document: dict[str, Any]) Any[source]

Inserts a document into the collection and returns the inserted document’s _id.

This method inserts a document into the collection after converting any bytes objects to Binary objects for proper JSON serialization and validating the resulting JSON string. It handles both databases with JSON1 support and those without by providing appropriate fallbacks.

Parameters:

document (dict) – The document to insert. Must be a dictionary.

Returns:

The auto-increment id of the inserted document.

Return type:

int

Raises:
  • MalformedDocument – If the document is not a dictionary

  • ValueError – If the document contains invalid JSON

  • sqlite3.Error – If database operations fail

_internal_replace(doc_id: Any, replacement: dict[str, Any])[source]

Replaces an entire document in the collection.

Parameters:
  • doc_id (Any) – The ID of the document to replace (can be ObjectId, int, etc.).

  • replacement (dict[str, Any]) – The new document to replace the existing one.

_internal_delete(doc_id: Any)[source]

Deletes a document from the collection based on the document ID.

Parameters:

doc_id (Any) – The ID of the document to delete (can be ObjectId, int, etc.).