Put
Command to create or replace an item in a DynamoDB table.
Example
Section titled “Example”import { DynamoTable, DynamoEntity, key, Put } from 'dynamo-document-builder';
const table = new DynamoTable({ tableName: 'ExampleTable', documentClient,});
const userEntity = new DynamoEntity({ table, schema: z.object({ userId: z.string(), name: z.string(), email: z.string(), }), partitionKey: user => key('USER', user.userId), sortKey: () => 'METADATA',});
const putCommand = new Put({ item: { userId: 'user123', name: 'John Doe', email: 'john@example.com', }, returnValues: 'ALL_OLD',});
const { returnItem } = await userEntity.send(putCommand);Type Parameters
Section titled “Type Parameters”Schema
Section titled “Schema”Schema extends ZodObject
The Zod schema defining the structure of the entity.
Implements
Section titled “Implements”BaseCommand<PutResult<Schema>,Schema>WriteTransactable<Schema>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Put<Schema>(config): Put<Schema>;Parameters
Section titled “Parameters”config
Section titled “config”PutConfig<Schema>
Returns
Section titled “Returns”Put<Schema>
Methods
Section titled “Methods”buildItem()
Section titled “buildItem()”buildItem(entity): Promise< | output<Schema> & DynamoKey | input<Schema> & DynamoKey>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<
| output<Schema> & DynamoKey
| input<Schema> & DynamoKey>
execute()
Section titled “execute()”execute(entity): Promise<PutResult<Schema>>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<PutResult<Schema>>
Implementation of
Section titled “Implementation of”prepareWriteTransaction()
Section titled “prepareWriteTransaction()”prepareWriteTransaction(entity): Promise<TransactWriteOperation>;Parameters
Section titled “Parameters”entity
Section titled “entity”DynamoEntity<Schema>
Returns
Section titled “Returns”Promise<TransactWriteOperation>