-
Notifications
You must be signed in to change notification settings - Fork 108
/
conditionalWrites.js
46 lines (38 loc) · 1.08 KB
/
conditionalWrites.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const dynogels = require('../index');
const Joi = require('joi');
const AWS = dynogels.AWS;
dynogels.dynamoDriver(new AWS.DynamoDB({
endpoint: 'http://localhost:8000',
region: 'eu-west-1',
}));
const Account = dynogels.define('example-Account', {
hashKey: 'AccountId',
timestamps: true,
schema: {
AccountId: Joi.string(),
name: Joi.string(),
email: Joi.string().email(),
age: Joi.number(),
}
});
dynogels.createTables({
'example-Account': { readCapacity: 1, writeCapacity: 10 },
}, (err) => {
if (err) {
console.log('Error creating tables', err);
process.exit(1);
}
const n = 2001;
const account = { AccountId: `${n}`, name: `Account ${n}`, email: `account${n}@gmail.com`, age: n };
Account.create(account, (err, a1) => {
console.log(err || a1.attrs);
const params = {};
params.ConditionExpression = '#i <> :x';
params.ExpressionAttributeNames = { '#i': 'age' };
params.ExpressionAttributeValues = { ':x': n };
Account.create(account, params, (err, a2) => {
console.log(err || a2.attrs);
});
});
});