Last active
May 7, 2020 16:25
-
-
Save Aposhian/2ba0f073fcd5f9b995ce5afd51ce21b3 to your computer and use it in GitHub Desktop.
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
const dynamoose = require('dynamoose') | |
const AWS = require('aws-sdk') | |
const { v4: uuid } = require('uuid') | |
const credentials = new AWS.Credentials('akid', 'secret', 'session') | |
const ddb = new AWS.DynamoDB({ | |
credentials, | |
region: 'us-east-1', | |
endpoint: 'http://localhost:8000' | |
}) | |
dynamoose.aws.ddb.set(ddb) | |
const schema = new dynamoose.Schema({ | |
hashKey: { | |
type: String, | |
hashKey: true | |
}, | |
rangeKey: { | |
type: String, | |
rangeKey: true, | |
index: { | |
global: true, | |
name: 'gsi1' | |
} | |
}, | |
gsiAttribute: { | |
type: String, | |
index: { | |
global: true, | |
name: 'gsi2' | |
} | |
}, | |
otherAttribute: String | |
}) | |
const Model = dynamoose.model('MyTable', schema, { | |
create: true, | |
waitForActive: true | |
}) | |
const main = async () => { | |
const document = { | |
hashKey: uuid(), | |
rangeKey: uuid(), | |
gsiAttribute: uuid(), | |
otherAttribute: uuid() | |
} | |
// This doesn't work | |
await Model.update({ | |
hashKey: document.hashKey, | |
rangeKey: document.rangeKey, | |
otherAttribute: document.otherAttribute | |
}) | |
// This doesn't work | |
await Model.update({ | |
hashKey: document.hashKey, | |
rangeKey: document.rangeKey, | |
gsiAttribute: document.gsiAttribute, | |
otherAttribute: document.otherAttribute | |
}) | |
// But this does work | |
await Model.update({ | |
hashKey: document.hashKey, | |
rangeKey: document.rangeKey | |
}, { | |
gsiAttribute: document.gsiAttribute, | |
otherAttribute: document.otherAttribute | |
}) | |
// And this works | |
await Model.update({ | |
hashKey: document.hashKey, | |
rangeKey: document.rangeKey | |
}, { | |
otherAttribute: document.otherAttribute | |
}) | |
} | |
main().catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment