Document Condition and KeyCondition
dimaqq opened this issue · comments
I can't figure out what the difference between Condition
and KeyCondition
is 😢
I can't figure out what the difference between
Condition
andKeyCondition
is 😢
KeyCondition
can be thought of as a specialized version of Condition
that only works on the key fields. They are constructed with HashKey(field, value)
(since the hash key always needs to be set to an exact value) and can optionally be combined with a RangeKey(field).<operation>(...)
.
Condition
on the other hand do not care about which field they operate on, so they are constructed with F(path).<operation>(...)
and can be combined freely.
KeyCondition
is special to prevent mistakes, such as for example trying to do F("hash_key").lt(12)
which is not allowed in Dynamo.
aiodynamos KeyCondition
is used to build a KeyConditionExpression
in DynamoDB, while aiodynamos Condition
is used to build a ConditionExpression
.
Okay I can see the intention.
Looking over this code though, it's a bit confusing, because:
- partition key can only equal something (in a query operation), while
- sort key can equal/being with/lt/gt/etc.
Meanwhile, both partition and partition + sort key (and their values) are both KeyCondition
s 🤷🏿
aiodynamo/src/aiodynamo/expressions.py
Lines 229 to 245 in fc179f3
Guys, how can i write a query after a certain GlboalSecondary index that a table contains ? how would the query look in aiodynamo ?(can't seem to figure it out)
Guys, how can i write a query after a certain GlboalSecondary index that a table contains ? how would the query look in aiodynamo ?(can't seem to figure it out)
could you explain it a bit more? are you trying to do a query(...)
on a secondary index? Are you looking for query("table-name", HashKey("secondary-index-key-field", "value"), index="name-of-secondary-index")
?
Yep that's the one thanks. Was a bit confused but now it makes sense,
HashKey("secondary-index-key-field", "value")
- this was the part that was a bit unclear. (didn't know how to compose the underlying KeyCondition for the GlobalSecondaryIndex but HashKey function fills both roles)
Can someone help me with an example of doing a query on a table ?
I really am confused as to how to put a KeyCondition in a query operation.
Can someone help me with an example of doing a query on a table ? I really am confused as to how to put a KeyCondition in a query operation.
can you describe what you're trying to do and what they key schema of your table is?
I'm also not sure of how to do a particular query. Can someone help me query the following table using aiodynamo - I want to find all id
s that include "ABCDEF" in their players
map:
{ "id": { "S": "123456" }, "players": { "M": { "ABCDEF": { "M": { "name": { "S": "kipkoan" } } } } } }
I'm also not sure of how to do a particular query. Can someone help me query the following table using aiodynamo - I want to find all
id
s that include "ABCDEF" in theirplayers
map:
F("players", "ABCDEF").exists()
Thanks, @ojii , that worked great!