Skip to content

indexKey

function indexKey(...parts): string | undefined;

Builds a DynamoDB key from the given parts. This function is specifically for secondary index keys, where any part can be undefined. If any part is undefined, the function returns undefined.

For primary keys, use the key function instead.

This is specifically useful for building keys for queries on secondary indexes, or for sparse indexes.

DynamoIndexKeyableValue[]

The parts to combine into a key.

string | undefined

The combined key as a string, or undefined if any part is undefined.

const key1 = indexKey('part1', 'part2', 'part3') // 'part1#part2#part3'
const key2 = indexKey('part1', undefined, 'part3') // undefined
const key3 = indexKey(undefined, 'part2', 'part3') // undefined
const key4 = indexKey('part1', 'part2', undefined) // undefined