Created
August 13, 2020 17:17
-
-
Save saibotsivad/3f3652a04bf41dd72fb098be73160e9a to your computer and use it in GitHub Desktop.
Example attempting to combine two operations into one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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