Conditions¶
DynamoDB query condition builders.
ConditionBaseTranslator ¶
deserialize_condition
classmethod
¶
deserialize_condition(condition_expression, is_key=True)
Convert ConditionBase Expression into ConditionBase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_expression
|
Union[str, ConditionBaseExpression]
|
The expression to convert. |
required |
is_key
|
bool
|
Used to infer attribute name if expression is string. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
ConditionBase
|
The deserialized ConditionBase. |
Source code in src/aibs_informatics_aws_utils/dynamodb/conditions.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
ConditionExpressionComponents
dataclass
¶
ConditionExpressionComponents(
expression,
expression_attribute_names,
expression_attribute_values,
)
Bases: ExpressionComponentsBase
fix_collisions ¶
fix_collisions(other)
Modify other expression components such that no attribute name/values collide.
Example
Given the following Expression components:
this = ConditionExpressionComponents(
"#n0 = :v0", {"#n0": "key1"}, {":v0": {"S": "str_value"}}
)
other = ConditionExpressionComponents(
"#n0 = :v1", {"#n0": "key2"}, {":v1": {"S": "str_value"}}
)
There is a collision of the attribute name #n0 which would get converted to #n1:
output = ConditionExpressionComponents(
"#n1 = :v1", {"#n1": "key2"}, {":v1": {"S": "str_value"}}
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
ConditionExpressionComponents
|
The other Expression Condition to modify. |
required |
Returns:
| Type | Description |
|---|---|
ConditionExpressionComponents
|
The other, as a modified non-overlapping Expression Condition. |
Source code in src/aibs_informatics_aws_utils/dynamodb/conditions.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
from_condition
classmethod
¶
from_condition(condition, is_key_condition)
Create ConditionExpressionComponents from a ConditionBase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition
|
ConditionBase
|
The ConditionBase to create expression components from. |
required |
is_key_condition
|
bool
|
If the provided condition is for a |
required |
Returns:
| Type | Description |
|---|---|
ConditionExpressionComponents
|
The created ConditionExpressionComponents. |
Source code in src/aibs_informatics_aws_utils/dynamodb/conditions.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
condition_to_str ¶
condition_to_str(condition)
Converts a ConditionBase Boto3 object to its str representation
NOTE: Function should be removed if this PR is merged: https://github.com/boto/boto3/pull/3254
Examples:
condition_to_str(Key("name").eq("new_name") & Attr("description").begins_with("new")) (name = new_name AND begins_with(description, new))
condition_to_str(Attr("description").contains("cool")) contains(description, cool)
condition_to_str(None) None
Source code in src/aibs_informatics_aws_utils/dynamodb/conditions.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |