add comment about splitting update expression by operator keywords
This commit is contained in:
parent
b713eef491
commit
a0471b0407
1 changed files with 3 additions and 0 deletions
|
|
@ -116,7 +116,10 @@ class Item(BaseModel):
|
||||||
}
|
}
|
||||||
|
|
||||||
def update(self, update_expression, expression_attribute_names, expression_attribute_values):
|
def update(self, update_expression, expression_attribute_names, expression_attribute_values):
|
||||||
|
# Update subexpressions are identifiable by the operator keyword, so split on that and
|
||||||
|
# get rid of the empty leading string.
|
||||||
parts = [p for p in re.split(r'\b(SET|REMOVE|ADD|DELETE)\b', update_expression) if p]
|
parts = [p for p in re.split(r'\b(SET|REMOVE|ADD|DELETE)\b', update_expression) if p]
|
||||||
|
# make sure that we correctly found only operator/value pairs
|
||||||
assert len(parts) % 2 == 0, "Mismatched operators and values in update expression: '{}'".format(update_expression)
|
assert len(parts) % 2 == 0, "Mismatched operators and values in update expression: '{}'".format(update_expression)
|
||||||
for action, valstr in zip(parts[:-1:2], parts[1::2]):
|
for action, valstr in zip(parts[:-1:2], parts[1::2]):
|
||||||
values = valstr.split(',')
|
values = valstr.split(',')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue