Skip to content

ConditionalPut

Command to create or replace an item with a condition expression.

import { DynamoTable, DynamoEntity, key, ConditionalPut, notExists } 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(),
status: z.string(),
}),
partitionKey: user => key('USER', user.userId),
sortKey: () => 'METADATA',
});
const conditionalPutCommand = new ConditionalPut({
item: { userId: 'user123', name: 'John', status: 'active' },
condition: { status: 'draft' },
returnValuesOnConditionCheckFailure: 'ALL_OLD',
});
await userEntity.send(conditionalPutCommand);

Schema extends ZodObject

The Zod schema defining the structure of the entity.

new ConditionalPut<Schema>(config): ConditionalPut<Schema>;

ConditionalPutConfig<Schema>

ConditionalPut<Schema>

buildItem(entity): Promise<
| output<Schema> & DynamoKey
| input<Schema> & DynamoKey>;

DynamoEntity<Schema>

Promise< | output<Schema> & DynamoKey | input<Schema> & DynamoKey>


execute(entity): Promise<ConditionalPutResult<Schema>>;

DynamoEntity<Schema>

Promise<ConditionalPutResult<Schema>>

BaseCommand.execute


prepareWriteTransaction(entity): Promise<TransactWriteOperation>;

DynamoEntity<Schema>

Promise<TransactWriteOperation>

WriteTransactable.prepareWriteTransaction