UNPKG

@moicky/dynamodb

Version:

Contains a collection of convenience functions for working with AWS DynamoDB

54 lines (53 loc) 2.1 kB
import { BatchWriteItemCommandInput, BatchWriteItemCommandOutput, PutItemCommandOutput, PutItemCommandInput as _PutItemCommandInput } from "@aws-sdk/client-dynamodb"; import { DynamoDBItem } from "../types"; type PutItemCommandInput = Omit<_PutItemCommandInput, "ReturnValues"> & { ReturnValues?: "NONE" | "ALL_OLD" | "ALL_NEW"; }; /** * Inserts an item into the DynamoDB table. * @param item - The item to insert into the table. * @param args - The additional arguments to override or specify for {@link PutItemCommandInput} * @returns A promise that resolves to the output of {@link PutItemCommandOutput} or the unmarshalled attributes if 'ReturnValues' is specified in 'args'. * * @example * Put a single item into DynamoDB * ```javascript * await putItem({ * PK: "User/1", * SK: "Book/1", * title: "The Great Gatsby", * author: "F. Scott Fitzgerald", * released: 1925, * }); * ``` */ export declare function putItem<T extends DynamoDBItem>(item: T, args: Partial<PutItemCommandInput> & { ReturnValues: string; }): Promise<T>; export declare function putItem<T extends DynamoDBItem, K extends Partial<PutItemCommandInput> = Partial<PutItemCommandInput>>(item: T, args?: K): Promise<PutItemCommandOutput>; type PutItemsArgs = Partial<BatchWriteItemCommandInput & { TableName?: string; }>; /** * Inserts multiple items into the DynamoDB table. * @param items - The items to insert into the table. * @param args - The additional arguments to override or specify for {@link PutItemsArgs} * @returns A promise that resolves to an array of {@link BatchWriteItemCommandOutput} * * @example * Put multiple items into DynamoDB * ```javascript * await putItems([ * { * PK: "User/1", * SK: "Book/1", * title: "The Great Gatsby", * author: "F. Scott Fitzgerald", * released: 1925, * }, * // ... infinite more items (will be grouped into batches of 25 due to aws limit) * ]); * ``` */ export declare function putItems(items: DynamoDBItem[], args?: PutItemsArgs, retry?: number): Promise<BatchWriteItemCommandOutput[]>; export {};