put
Introduction
put method performs put request using aws-sdk PutItemCommand.
In addition to PutItemCommandOutput, put response will include Item which is fully typed based on your Schema declaration.
Item is usefull as your Schema may include default, set or other transformer options.
execute
put takes 2 arguments:
- (required) Item
- (optionnal) conditions
- (optionnal) options
any invalid value in Item will lead to dev time and runtime error
const res = await User.put(
{
id: "user-1",
age: 27,
firstname: "John",
sex: "male",
data: "something",
},
{
firstname: {
$startsWith: "Jo"
},
},
{ ReturnConsumedCapacity: "TOTAL" }
);
options
options is an object which accepts PutItemCommandInput options and DynamoQL specific options.
exec
exec boolean directive to execute or not the actual request.
When false put will return PutItemCommandInput object.
import type { PutItemCommandInput } from "@aws-sdk/client-dynamodb";
const cmd: PutItemCommandInput = await User.put(
{
id: "user-1",
age: 27,
firstname: "John",
sex: "male",
data: "something",
},
undefined, // no condition
{ exec: false }
);
setterInfo
setterInfo allows you to pass any value to your Schema set function's third argument.
const res = await User.put(
{
id: "user-1",
age: 27,
firstname: "John",
sex: "male",
data: "something",
},
undefined, // no condition
{ setterInfo: { generateHash: true } }
);