dyna-record
    Preparing search index...

    Type Alias TypedSortKeyCondition<T>

    TypedSortKeyCondition:
        | SortKeyValueFor<T>
        | { $beginsWith: SortKeyValueFor<T> | Prefixes<PartitionEntityNames<T>> }
        | SingleComparisonFilter<SortKeyValueFor<T>>
        | BetweenFilter<SortKeyValueFor<T>>

    Typed sort key condition for querying within an entity's partition.

    In dyna-record's single-table design, sort key values always start with an entity class name — either the entity itself or one of its declared relationships (@HasMany, @HasOne, @BelongsTo, @HasAndBelongsToMany):

    • Self/HasOne records: SK = "EntityName" (exact entity name)
    • HasMany records: SK = "EntityName#id" (entity name + delimiter + id)

    This type restricts skCondition and the sk key condition to only accept the entity's own name or its related entity names (or prefixes thereof). Unrelated entities and entities from other tables are rejected at compile time.

    The $beginsWith variant also accepts partial entity name prefixes — e.g. $beginsWith: "Inv" is valid when the partition contains "Invoice" and "Inventory", since DynamoDB's begins_with would match both entity types.

    A comparison or a $between range is also accepted, and is where a key condition earns its keep: it narrows what DynamoDB reads, where a filter discards rows already read. DynamoDB has room for exactly one condition on the sort key, so the comparison operators do not compose here — a two-sided range is $between.

    Type Parameters

    • T extends default

      The entity type being queried.

    // One entity type within the partition
    skCondition: { $beginsWith: "Order" }

    // A one-sided range over the sort key
    skCondition: { $gte: "Order#100" }

    // A two-sided range, which must be $between
    skCondition: { $between: ["Order#100", "Order#200"] }