The dbzero.assign() method provides a convenient way to perform bulk attribute updates on one or more Memo objects. It allows you to set multiple attributes to new values in a single, readable command.
Signature
db0.assign(*objects, **attributes)Parameters
| Parameter | Type | Description |
|---|---|---|
*objects | Memo instance(s) | One or more Memo objects whose attributes you want to update. |
**attributes | keyword arguments | The attributes to update, provided as name=value pairs. |
Returns
This method does not return any value.
Side Effects
The method directly modifies the attributes of the provided Memo object(s). These changes are immediately reflected in the objects and persisted by dbzero.
Examples
Updating a Single Object
You can easily update several attributes on a single object at once.
# Create an object with initial values
obj = MemoTestThreeParamsClass(value_1=1, value_2=2, value_3=3)
# Use assign() to update its attributes
db0.assign(obj, value_1=4, value_2=5)
# The object's attributes are now updated
assert obj.value_1 == 4
assert obj.value_2 == 5
assert obj.value_3 == 3 # This one was not changedUpdating Multiple Objects
assign() can apply the same changes to multiple objects in one call, which is great for batch operations.
# Create two objects
obj_1 = MemoTestThreeParamsClass(1, 2, 3)
obj_2 = MemoTestThreeParamsClass(1, 2, 3)
# Assign new values to both objects simultaneously
db0.assign(obj_1, obj_2, value_1=10, value_2=20)
# Verify the changes on the first object
assert obj_1.value_1 == 10
assert obj_1.value_2 == 20
# Verify the changes on the second object
assert obj_2.value_1 == 10
assert obj_2.value_2 == 20<div className="bg-blue-100/50 dark:bg-blue-900/10 border-l-4 border-blue-400 dark:border-blue-600 p-4 my-4 rounded-r-lg" role="alert" > Note on Atomicity
For operations where it's critical that all assignments succeed or none do (i.e., an atomic transaction), dbzero provides dbzero.atomic_assign(). It uses the same signature as dbzero.assign() but ensures the entire operation is treated as a single, indivisible unit.
db0.atomic_assign(obj, value_1=4, value_2=5)</div>