prorm API Reference
    Preparing search index...

    Class DynamoDbStore

    Amazon DynamoDB store, implementing the minimal NoSqlStore marker interface. Unlike the SQL dialects, there is no query(sql) — DynamoDB's operations are item/key-shaped (Get/Put/Update/Delete/Query/Scan/Batch/Transact), and that shape is preserved here rather than forced into a SQL string.

    Implements

    Index
    name: "dynamodb" = 'dynamodb'

    The name of the store (e.g. 'mongodb', 'redis', 'dynamodb')

    library: "@aws-sdk/client-dynamodb" = '@aws-sdk/client-dynamodb'

    The client library being used

    • Returns the DynamoDBDocumentClient (plain-object marshalling), not the raw DynamoDBClient.

      Returns DynamoDBDocumentClient

    • Access to the low-level DynamoDBClient (raw AttributeValue shapes), for anything the document client doesn't cover.

      Returns DynamoDBClient

    • Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • key: DynamoDbItem
      • options: { consistentRead?: boolean; projectionExpression?: string } = {}

      Returns Promise<T | undefined>

    • options.returnValues defaults to 'NONE' (matching real PutItem default behavior). Pass 'ALL_OLD' to get the item's previous value back (undefined if there wasn't one).

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      Returns Promise<T | undefined>

    • Convenience update: SETs each key in updates to its value. Builds a simple UpdateExpression/ExpressionAttributeValues internally, using #k0, #k1, ... as attribute name placeholders (so reserved words like status are always safe) merged with any options.expressionAttributeNames. For REMOVE/ADD/DELETE or nested-path updates, use updateItemRaw().

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • key: DynamoDbItem
      • updates: UpdateAttributes
      • options: UpdateItemOptions = {}

      Returns Promise<T | undefined>

    • Escape hatch for update expressions beyond the flat-SET convenience wrapper above (REMOVE/ADD/DELETE, nested paths, etc).

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • input: UpdateCommandInput

      Returns Promise<T | undefined>

    • options.returnValues defaults to 'ALL_OLD' (returns the deleted item); pass 'NONE' to skip returning it.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      Returns Promise<T | undefined>

    • Query by partition key equality (plus an optional sort-key condition) against the base table or a named GSI/LSI. This is the primary way to read more than one item efficiently from DynamoDB — unlike Scan, it only reads the partition(s) that match, not the whole table.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      Returns Promise<DynamoQueryResult<T>>

    • Full table (or index) scan. This reads every item in the table — cost and latency scale with table size, not with how many items you actually want, and filterExpression is applied after the read (it does not reduce RCU consumption or the amount of data scanned). Prefer query() with a well-designed partition/sort key or GSI. Only reach for scan() for admin/maintenance/export tasks, small tables, or as a last resort when no query-friendly access pattern exists.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      Returns Promise<ScanResult<T>>

    • Auto-paginating query(): DynamoDB caps each Query response at 1MB of data, so a query over more items than that fits in a single page and returns a lastEvaluatedKey that the caller must pass back in as exclusiveStartKey to fetch the next page. Forgetting to loop on that silently truncates results. queryAll() follows lastEvaluatedKey automatically and returns every matching item across all pages.

      params.limit, if set, still applies per-page (as DynamoDB defines it) — it does not cap the total number of items returned here. To consume pages one at a time instead of buffering everything in memory, use queryPages().

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      Returns Promise<T[]>

    • Async-generator form of queryAll(): yields each page of items as it arrives instead of buffering the entire result set in memory, while still following lastEvaluatedKey automatically.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      Returns AsyncGenerator<T[], void, void>

    • Auto-paginating scan() — see queryAll() above for why this matters (the same 1MB-per-page cap applies to Scan). Reminder: scan() is already O(table size) per the warning on scan() itself; scanAll() makes that even more explicit by reading literally the whole table (or index) into memory across as many pages as it takes.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      Returns Promise<T[]>

    • Async-generator form of scanAll(); yields each page as it arrives.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      Returns AsyncGenerator<T[], void, void>

    • BatchGetItem across one or more tables. DynamoDB caps a single BatchGetItem call at 100 items total; this method chunks keys internally (25-at-a-time chunks well under the limit, sent sequentially) so callers can pass an arbitrarily large key list without worrying about the limit themselves. Also retries any UnprocessedKeys DynamoDB returns for a chunk (throttling) with exponential backoff and jitter between attempts, up to options.maxAttempts (default 5) attempts per chunk, before giving up and returning whatever's still unprocessed to the caller.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • keys: DynamoDbItem[]
      • options: { consistentRead?: boolean; chunkSize?: number } & BatchRetryOptions = {}

      Returns Promise<{ items: T[]; unprocessedKeys: DynamoDbItem[] }>

    • BatchWriteItem (put and/or delete) against a single table. DynamoDB caps a single BatchWriteItem call at 25 write requests; this method chunks requests internally so callers can pass an arbitrarily large batch. Also retries UnprocessedItems with exponential backoff and jitter, up to options.maxAttempts (default 5) attempts per chunk, before returning whatever's left to the caller.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • requests: ({ put?: T } | { delete: DynamoDbItem })[]
      • options: { chunkSize?: number } & BatchRetryOptions = {}

      Returns Promise<{ unprocessedCount: number }>

    • Passthrough to DynamoDB's TransactWriteItems — up to 100 Put/Update/ Delete/ConditionCheck actions, atomically, potentially across multiple tables. Not chunked: DynamoDB rejects the whole transaction if it exceeds the limit, so it's on the caller to stay under it (unlike the batch methods above, there's no safe way to silently split a transaction into several without breaking its atomicity guarantee).

      Parameters

      • input: Omit<TransactWriteCommandInput, "TransactItems"> & {
            transactItems:
                | (
                    Omit<
                        TransactWriteItem,
                        "ConditionCheck"
                        | "Put"
                        | "Delete"
                        | "Update",
                    > & {}
                )[]
                | undefined;
        }

      Returns Promise<void>

    • Passthrough to DynamoDB's TransactGetItems — up to 100 Get actions, read as a single consistent snapshot.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • input: Omit<TransactGetCommandInput, "TransactItems"> & {
            transactItems: (Omit<TransactGetItem, "Get"> & {})[] | undefined;
        }

      Returns Promise<(T | undefined)[]>

    • Enables DynamoDB Streams on a table via UpdateTableCommand's StreamSpecification, choosing what a stream record captures: KEYS_ONLY (just the key attributes of the modified item), NEW_IMAGE (the entire item as it appears after modification), OLD_IMAGE (as it appeared before), or NEW_AND_OLD_IMAGES (both). This only flips the table-level setting and returns the ARN DynamoDB assigns the new stream — it does not read from the stream itself; see "Known limitations" in the README for why a stream consumer is out of scope for this store.

      Parameters

      Returns Promise<string | undefined>

    • Disables DynamoDB Streams on a table via UpdateTableCommand.

      Parameters

      • tableName: string

      Returns Promise<void>

    • Reads back the table's current stream ARN (undefined if streams aren't enabled) via DescribeTableCommand. Consuming the stream itself (shard iterators / record polling) requires the separate @aws-sdk/client-dynamodb-streams package or a Lambda event source mapping — out of scope here, see the README.

      Parameters

      • tableName: string

      Returns Promise<string | undefined>

    • Enables TTL on a table via UpdateTimeToLiveCommand: DynamoDB periodically (usually within 48 hours, not immediately) deletes items whose attributeName holds a Unix epoch-seconds number in the past. A table may only have one TTL attribute at a time.

      Parameters

      • tableName: string
      • attributeName: string

      Returns Promise<void>

    • Disables TTL on a table. DynamoDB requires the currently-enabled AttributeName to be repeated on the disabling call, so this first reads it back via describeTTL() and is a no-op if TTL isn't currently enabled on the table.

      Parameters

      • tableName: string

      Returns Promise<void>

    • Reads back a table's TTL configuration via DescribeTimeToLiveCommand.

      Parameters

      • tableName: string

      Returns Promise<
          {
              status: TimeToLiveStatus
              | undefined;
              attributeName: string | undefined;
          },
      >

    • Creates a table via CreateTableCommand. Thin passthrough to the raw SDK input shape: params.TableName, params.KeySchema, and params.AttributeDefinitions are required (as real CreateTable requires), plus either params.BillingMode: 'PAY_PER_REQUEST' or params.ProvisionedThroughput (real CreateTable requires one or the other), and optionally params.GlobalSecondaryIndexes/ params.LocalSecondaryIndexes. Table creation is asynchronous on AWS's side (the table starts in CREATING status) — this call returns as soon as DynamoDB accepts the request, it does not wait for the table to become ACTIVE; poll describeTable() if you need to wait.

      Parameters

      • params: CreateTableCommandInput

      Returns Promise<TableDescription | undefined>

    • Deletes a table via DeleteTableCommand. Like createTable(), this is asynchronous on AWS's side (the table moves to DELETING status); this call returns as soon as DynamoDB accepts the request.

      Parameters

      • tableName: string

      Returns Promise<TableDescription | undefined>

    • Lists table names in the current account/region via ListTablesCommand. A single call returns at most 100 table names (or params.limit if lower); pass params.exclusiveStartTableName (from a previous call's lastEvaluatedTableName) to page through the rest.

      Parameters

      • params: { exclusiveStartTableName?: string; limit?: number } = {}

      Returns Promise<ListTablesResult>

    • Reads back a table's full description (status, key schema, billing mode, indexes, stream ARN, item count, etc.) via DescribeTableCommand. getStreamArn() above is a narrow convenience wrapper around this same command for just the stream ARN.

      Parameters

      • tableName: string

      Returns Promise<TableDescription | undefined>

    • Adds or removes a Global Secondary Index on an existing table via UpdateTableCommand's GlobalSecondaryIndexUpdates. DynamoDB only allows one GSI create/delete/update action per UpdateTable call, so gsiUpdates must contain exactly one GlobalSecondaryIndexUpdate entry ({ Create: {...} }, { Update: {...} }, or { Delete: {...} }). When creating a new GSI, attributeDefinitions must include the key attribute(s) of the new index (DynamoDB validates this).

      Parameters

      • tableName: string
      • gsiUpdates: GlobalSecondaryIndexUpdate[]
      • OptionalattributeDefinitions: AttributeDefinition[]

      Returns Promise<TableDescription | undefined>

    • Switches a table between on-demand (PAY_PER_REQUEST) and provisioned (PROVISIONED) capacity via UpdateTableCommand. When switching to PROVISIONED, throughput (ReadCapacityUnits/WriteCapacityUnits) is required (real DynamoDB rejects the call without it); it's ignored when switching to PAY_PER_REQUEST.

      Parameters

      • tableName: string
      • mode: BillingMode
      • Optionalthroughput: ProvisionedThroughput

      Returns Promise<TableDescription | undefined>

    • Enables Point-in-Time Recovery on a table via UpdateContinuousBackupsCommand, allowing restore to any second within the retention window (35 days by default; DynamoDB currently ignores a custom recoveryPeriodInDays on enable and defaults to 35).

      Parameters

      • tableName: string

      Returns Promise<void>

    • Disables Point-in-Time Recovery on a table via UpdateContinuousBackupsCommand.

      Parameters

      • tableName: string

      Returns Promise<void>

    • Reads back a table's PITR configuration via DescribeContinuousBackupsCommand.

      Parameters

      • tableName: string

      Returns Promise<PitrDescription>

    • Creates an on-demand backup of a table via CreateBackupCommand.

      Parameters

      • tableName: string
      • backupName: string

      Returns Promise<BackupDetails | undefined>

    • Reads back a backup's full description via DescribeBackupCommand.

      Parameters

      • backupArn: string

      Returns Promise<BackupDescription | undefined>

    • Lists backups via ListBackupsCommand, optionally scoped to a single table. Does not auto-paginate — pass the last item's BackupArn back in as exclusiveStartBackupArn to fetch the next page, same pattern as listTables().

      Parameters

      • OptionaltableName: string
      • options: { limit?: number; exclusiveStartBackupArn?: string } = {}

      Returns Promise<BackupSummary[]>

    • Restores a backup into a new table via RestoreTableFromBackupCommand. DynamoDB always restores into a new table (newTableName must not already exist) — it does not overwrite the original table the backup was taken from. Like createTable(), this is asynchronous: the new table starts in CREATING status.

      Parameters

      • backupArn: string
      • newTableName: string

      Returns Promise<TableDescription | undefined>

    • Adds (or updates, if the key already exists) tags on a table/backup resource via TagResourceCommand.

      Parameters

      • resourceArn: string
      • tags: Record<string, string> | Tag[]

      Returns Promise<void>

    • Removes tags (by key) from a table/backup resource via UntagResourceCommand.

      Parameters

      • resourceArn: string
      • tagKeys: string[]

      Returns Promise<void>

    • Lists tags on a table/backup resource via ListTagsOfResourceCommand. Does not auto-paginate — pass a returned nextToken back in as options.nextToken to fetch the next page.

      Parameters

      • resourceArn: string
      • options: { nextToken?: string } = {}

      Returns Promise<{ tags: Tag[]; nextToken?: string }>

    • Fetch items matching the ORM where clause. When options.key pins the partition key by equality this issues an efficient Query; otherwise it falls back to a Scan (see the warning on scan). Returns a single page plus the lastEvaluatedKey cursor (pass it back as exclusiveStartKey for the next page, or use findAll to auto-paginate).

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • options: DynamoFindOptions = {}

      Returns Promise<DynamoQueryResult<T>>

    • Auto-paginating findAllPaged: follows lastEvaluatedKey and returns every matching item. options.limit still applies per page (as DynamoDB defines it); to cap total results, slice the return value.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • options: DynamoFindOptions = {}

      Returns Promise<T[]>

    • Fetch the first item matching where (page-limited to 1), or undefined.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • options: DynamoFindOptions = {}

      Returns Promise<T | undefined>

    • Count items matching where using Select: 'COUNT' (server-side count; items are not returned). Follows pagination automatically and sums each page's count.

      Parameters

      • tableName: string
      • options: DynamoFindOptions = {}

      Returns Promise<number>

    • Insert an item (PutItem). By default overwrites any existing item with the same key (native Put semantics); pass options.key with options.insertOnly to add an attribute_not_exists(<pk>) condition so a duplicate primary key fails instead (SQL INSERT semantics).

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • item: T
      • options: { key?: DynamoKeySchema; insertOnly?: boolean } = {}

      Returns Promise<T>

    • Insert many items via chunked/retried BatchWriteItem puts.

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • items: T[]
      • options: BatchRetryOptions & { chunkSize?: number } = {}

      Returns Promise<{ inserted: number; unprocessedCount: number }>

    • Insert-or-replace an item (PutItem) — DynamoDB's native Put already has upsert semantics (it creates the item or overwrites it wholesale).

      Type Parameters

      • T extends DynamoDbItem = DynamoDbItem

      Parameters

      • tableName: string
      • item: T

      Returns Promise<T>

    • Update every item matching where, SETting each key in values. When where pins the full primary key (and nothing else), this is a single UpdateItem; otherwise it finds matching items (Query/Scan via key), then issues one UpdateItem per item. Requires options.key. Returns the number of items updated.

      Parameters

      • tableName: string
      • values: UpdateAttributes
      • where: Record<string, any>
      • options: { key: DynamoKeySchema; indexName?: string } = ...

      Returns Promise<number>

    • Delete every item matching where. When where pins the full primary key this is a single DeleteItem; otherwise it finds matching items and deletes them via chunked BatchWriteItem. Requires options.key. Returns the number of items deleted.

      Parameters

      • tableName: string
      • where: Record<string, any>
      • options: { key: DynamoKeySchema; indexName?: string } = ...

      Returns Promise<number>