updateItem

Spec

async updateItem(
    tnmInput: TynamoUpdateItemInput<TSource>
): Promise<TynamoUpdateItemOutput<TSource>>

Input

export interface TynamoUpdateItemInput<TSource> {
    Key: Partial<TSource>;
    ExpressionAttributeValues?: any;
    
    // Derived from DynamoDB.
    ReturnValues?: ReturnValue;
    ReturnConsumedCapacity?: ReturnConsumedCapacity;
    ReturnItemCollectionMetrics?: ReturnItemCollectionMetrics;
    ConditionExpression?: ConditionExpression;
    UpdateExpression?: UpdateExpression;
    ExpressionAttributeNames?: ExpressionAttributeNameMap;
}

Unlisted param is derived from DynamoDB.

Check here for more information.

Output

export interface TynamoUpdateItemOutput<TSource> {
    Attributes?: TSource;

    // Derived from DynamoDB.
    $response: AWS.Response<UpdateItemOutput, AWS.AWSError>;    
    ConsumedCapacity?: ConsumedCapacity;
    ItemCollectionMetrics?: ItemCollectionMetrics;
}

Unlisted param is derived from DynamoDB.

Check here for more information.

Example

@DynamoEntity()
class Cat {
    @DynamoProperty({ keyType: KeyType.hash })
    id!: number;

    @DynamoProperty({ keyType: KeyType.attr })
    name!: string;

    constructor(id: number, name: string) {
        this.id = id;
        this.name = name;
    }
}

@DynamoEntity()
class Args {
    @DynamoProperty({ keyType: KeyType.hash })
    name!: string;
    
    constructor(name: string){
        this.name = name;
    }
}

const tynamo: Tynamo = new Tynamo({
    region: "ap-northeast-2",
    endpoint: "http://localhost:8000"
});
const tynamoTable = tynamo.getTableOf(Cat);


await tynamoTable.updateItem({
    Key: new Cat(666, ""),
    UpdateExpression: "SET #name = :name",
    ExpressionAttributeValues: new Args("devil_cat")
});

Last updated