Skip to content

Instantly share code, notes, and snippets.

@saibotsivad
Created August 13, 2020 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saibotsivad/3f3652a04bf41dd72fb098be73160e9a to your computer and use it in GitHub Desktop.
Save saibotsivad/3f3652a04bf41dd72fb098be73160e9a to your computer and use it in GitHub Desktop.
Example attempting to combine two operations into one
async function ({ client, key, now }) => {
try {
await client.put({
TableName: 'my-table',
ConditionExpression: 'PrimaryPartitionKey <> :key',
ExpressionAttributeValues: {
':key': key
},
Item: {
PrimaryPartitionKey: key,
Data: {
expires: 0
}
}
}).promise()
} catch (error) {
console.log('the item already exists no big deal')
}
await client.put({
TableName: 'my-table',
ConditionExpression: '#data.#expires <= :now',
ExpressionAttributeValues: {
':now': now
},
ExpressionAttributeNames: {
'#data': 'Data',
'#expires': 'expires'
},
Item: {
PrimaryPartitionKey: key,
Data: {
expires: now + 100
}
}
}).promise()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment