mysqlx.ModifyStatementΒΆ
- class mysqlx.ModifyStatement(collection: DatabaseTargetType, condition: str)ΒΆ
Bases:
FilterableStatement
A statement for document update operations on a Collection.
- Parameters:
collection (mysqlx.Collection) β The Collection object.
condition (str) β Sets the search condition to identify the documents to be modified.
Changed in version 8.0.12: The
condition
parameter is now mandatory.- array_append(doc_path: str, value: Any) ModifyStatement ΒΆ
Inserts a value into a specific position in an array attribute in documents of a collection.
- Parameters:
doc_path (string) β A document path that identifies the array attribute and position where the value will be inserted.
value (object) β The value to be inserted.
- Returns:
ModifyStatement object.
- Return type:
- array_insert(field: str, value: Any) ModifyStatement ΒΆ
Insert a value into the specified array in documents of a collection.
- Parameters:
field (string) β A document path that identifies the array attribute and position where the value will be inserted.
value (object) β The value to be inserted.
- Returns:
ModifyStatement object.
- Return type:
- bind(*args: Any) FilterableStatement ΒΆ
Binds value(s) to a specific placeholder(s).
- Parameters:
*args β The name of the placeholder and the value to bind. A
mysqlx.DbDoc
object or a JSON string representation can be used.- Returns:
FilterableStatement object.
- Return type:
- Raises:
ProgrammingError β If the number of arguments is invalid.
- change(doc_path: str, value: Any) ModifyStatement ΒΆ
Add an update to the statement setting the field, if it exists at the document path, to the given value.
- Parameters:
doc_path (string) β The document path of the item to be set.
value (object) β The value to be set on the specified attribute.
- Returns:
ModifyStatement object.
- Return type:
Deprecated since version 8.0.12.
- property changed: boolΒΆ
True if this statement has changes.
- Type:
bool
- property deallocate_prepare_execute: boolΒΆ
True to deallocate + prepare + execute statement.
- Type:
bool
- property exec_counter: intΒΆ
The number of times this statement was executed.
- Type:
int
- execute() Result ΒΆ
Execute the statement.
- Returns:
Result object.
- Return type:
- Raises:
ProgrammingError β If condition was not set.
- get_binding_map() Dict[str, Any] ΒΆ
Returns the binding map dictionary.
- Returns:
The binding map dictionary.
- Return type:
dict
- get_bindings() Dict[str, Any] | List ΒΆ
Returns the bindings list.
- Returns:
The bindings list.
- Return type:
list
- get_grouping() List[ProtobufMessageType | ProtobufMessageCextType] ΒΆ
Returns the grouping expression list.
- Returns:
The grouping expression list.
- Return type:
list
- get_having() MessageType ΒΆ
Returns the having expression.
- Returns:
The having expression.
- Return type:
object
- get_limit_offset() int ΒΆ
Returns the limit offset.
- Returns:
The limit offset.
- Return type:
int
- get_limit_row_count() int ΒΆ
Returns the limit row count.
- Returns:
The limit row count.
- Return type:
int
- get_projection_expr() List[ProtobufMessageType | ProtobufMessageCextType] ΒΆ
Returns the projection expression.
- Returns:
The projection expression.
- Return type:
object
- get_sort_expr() List[ProtobufMessageType | ProtobufMessageCextType] ΒΆ
Returns the sort expression.
- Returns:
The sort expression.
- Return type:
object
- get_update_ops() Dict[str, Any] ΒΆ
Returns the list of update operations.
- Returns:
The list of update operations.
- Return type:
list
- get_where_expr() MessageType ΒΆ
Returns the where expression.
- Returns:
The where expression.
- Return type:
object
- increment_exec_counter() None ΒΆ
Increments the number of times this statement has been executed.
- is_doc_based() bool ΒΆ
Check if it is document based.
- Returns:
True if it is document based.
- Return type:
bool
- limit(row_count: int, offset: int | None = None) FilterableStatement ΒΆ
Sets the maximum number of items to be returned.
- Parameters:
row_count (int) β The maximum number of items.
- Returns:
FilterableStatement object.
- Return type:
- Raises:
ValueError β If
row_count
is not a positive integer.
Changed in version 8.0.12: The usage of
offset
was deprecated.
- offset(offset: int) FilterableStatement ΒΆ
Sets the number of items to skip.
- Parameters:
offset (int) β The number of items to skip.
- Returns:
FilterableStatement object.
- Return type:
- Raises:
ValueError β If
offset
is not a positive integer.
New in version 8.0.12.
- patch(doc: Dict | DbDoc | ExprParser | str) ModifyStatement ΒΆ
Takes a
mysqlx.DbDoc
, string JSON format or a dict with the changes and applies it on all matching documents.- Parameters:
doc (object) β A generic document (DbDoc), string in JSON format or dict, with the changes to apply to the matching documents.
- Returns:
ModifyStatement object.
- Return type:
- property prepared: boolΒΆ
True if this statement has been prepared.
- Type:
bool
- property repeated: boolΒΆ
True if this statement was executed more than once.
- Type:
bool
- reset_exec_counter() None ΒΆ
Resets the number of times this statement has been executed.
- property schema: SchemaTypeΒΆ
The Schema object.
- Type:
- set(doc_path: str, value: Any) ModifyStatement ΒΆ
Sets or updates attributes on documents in a collection.
- Parameters:
doc_path (string) β The document path of the item to be set.
value (string) β The value to be set on the specified attribute.
- Returns:
ModifyStatement object.
- Return type:
- sort(*clauses: str) ModifyStatement ΒΆ
Sets the sorting criteria.
- Parameters:
*clauses β The expression strings defining the sort criteria.
- Returns:
ModifyStatement object.
- Return type:
- property stmt_id: intΒΆ
Returns this statement ID.
- Returns:
The statement ID.
- Return type:
int
- property target: DatabaseTargetTypeΒΆ
The database object target.
- Type:
object
- unset(*doc_paths: str) ModifyStatement ΒΆ
Removes attributes from documents in a collection.
- Parameters:
doc_paths (list) β The list of document paths of the attributes to be removed.
- Returns:
ModifyStatement object.
- Return type:
- where(condition: str) FilterableStatement ΒΆ
Sets the search condition to filter.
- Parameters:
condition (str) β Sets the search condition to filter documents or records.
- Returns:
FilterableStatement object.
- Return type:
Deprecated since version 8.0.12.