async putItem<TSource>(
tnmInput: TynamoPutItemInput<TSource>
): Promise<TynamoPutItemOutput<TSource>>;
export interface TynamoPutItemInput<TSource> {
Item: TSource;
ExpressionAttributeValues?: any;
// Dervied from DynamoDB
ReturnValues?: ReturnValue;
ReturnConsumedCapacity?: ReturnConsumedCapacity;
ReturnItemCollectionMetrics?: ReturnItemCollectionMetrics;
ExpressionAttributeNames?: ExpressionAttributeNameMap;
ConditionExpression?: ConditionExpression;
}
export interface TynamoPutItemOutput<TSource> {
Attributes?: TSource;
// Derived from DynamoDB.
$response: AWS.Response<PutItemOutput, AWS.AWSError>;
ConsumedCapacity?: ConsumedCapacity;
ItemCollectionMetrics?: ItemCollectionMetrics;
}
@DynamoEntity()
class Cat {
@DynamoProperty({ keyType: KeyType.hash })
id!: number;
@DynamoProperty({ keyType: KeyType.attr })
name!: string;
constructor(id: number, name: string, favoriteNumbers: number[]) {
this.id = id;
this.name = name;
}
}
const tynamo: Tynamo = new Tynamo({
region: "ap-northeast-2",
endpoint: "http://localhost:8000"
});
const tynamoTable = tynamo.getTableOf(Cat);
// Insert if, garfield is not exist.
await tynamoTable.putItem({
Item: new Cat(666, "garfield"),
ConditionExpression: "attribute_not_exists(#id)"
});