Query
Intro
DynamoDB is very different from conventional RDS in many regards.
in order to use DynamoDB at it's best form, understanding the core concept of DynamoDB rather than blindly trying replicate the design patterns from RDS is crucial.
for this, DynamoDB Guide did fantastic job, we recommend to read it
on this chapter, we'll focus example of actual of "query" - retriving records from DynamoDB.
There are 5 different types of queryable enttiy in Dynamorm
But DynamoDB query patterns are identical, based on key type (Hash or Hash + Range)
In Dynamorm, we use the term "Hash" and "Full" for those.
Entity | Data Structure |
---|---|
HashPrimaryKey | Hash |
FullPrimaryKey | Hash + Range |
LocalSecondaryIndex | Hash (Same with PK) + Range |
HashGlobalSecondaryIndex | Hash (Can be different with PK) |
FullGlobalSecondaryIndex | Hash + Range (both can be different with PK) |
So for example, FullPrimaryKey and FullGlobalSecondaryIndex has almost identical query interface, except few APIs
HashPrimaryKey
.get(hashKey: HashKeyType, options: { consistent: boolean }): Promise<T | null>
find single record with hashKey, return null if record not exists
if the record is < 4KB, consumes 1 read capacity.
.scan(options)
(TBD)
.batchGet(hashKeys)
(TBD)
.batchGetFull()
(TBD)
FullPrimaryKey
.get(hashKey, sortKey, options)
(TBD)
.batchGet(keys)
(TBD)
.batchGetFull(keys)
(TBD)
.query(options)
(TBD)
.scan(options)
(TBD)
LocalSecondaryIndex
Identical to FullPrimaryKey
HashGlobalSecondaryIndex
Identical to HashPrimaryKey
FullGlobalSecondaryIndex
Identical to FullPrimaryKey