Skip to content

Commit 812b353

Browse files
committed
chore: test script
1 parent d6319b0 commit 812b353

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

src/test.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { DynamoHelper } from './DynamoHelper';
2+
import { ConditionExpressionKind, FilterOperators } from './types';
3+
4+
const table = {
5+
name: 'till-x-test-in',
6+
indexes: {
7+
default: {
8+
partitionKeyName: 'pk',
9+
sortKeyName: 'sk',
10+
},
11+
gsi1: {
12+
partitionKeyName: 'gs1pk',
13+
sortKeyName: 'gs1sk',
14+
},
15+
gsi2: {
16+
partitionKeyName: 'gs2pk',
17+
sortKeyName: 'gs2sk',
18+
},
19+
gsi3: {
20+
partitionKeyName: 'gs3pk',
21+
sortKeyName: 'gs3sk',
22+
},
23+
gsi4: {
24+
partitionKeyName: 'gs4pk',
25+
sortKeyName: 'gs4sk',
26+
},
27+
gsi5: {
28+
partitionKeyName: 'gs5pk',
29+
sortKeyName: 'gs5sk',
30+
},
31+
gsi6: {
32+
partitionKeyName: 'gs6pk',
33+
sortKeyName: 'gs6sk',
34+
},
35+
},
36+
};
37+
const client = new DynamoHelper(table, 'ap-southeast-1');
38+
39+
client
40+
.query({
41+
where: {
42+
pk: 'store#37059ae2-dfb9-40c8-953a-f68aa872c86a#settings',
43+
appVersion: { exists: false },
44+
},
45+
})
46+
.then(x => console.log(x, '\n len: ' + x.length));
47+
48+
client
49+
.query(
50+
{
51+
where: {
52+
gs1pk: 'deviceprofile#d0c622d0-4343-4583-9c02-54b1865cf609',
53+
appVersion: { exists: true },
54+
},
55+
},
56+
'gsi1',
57+
)
58+
.then(x => console.log(x, '\n len: ' + x.length));
59+
60+
async function testConditionalUpdateItem() {
61+
const storeId = '61da543d-1252-45b9-bc98-389c40d96761';
62+
const updatedOrder = {
63+
pk: `STORE#${storeId}`,
64+
sk: 'open-shift',
65+
status: 'open',
66+
updatedAt: new Date().toISOString(),
67+
};
68+
await client.updateItem(
69+
{ pk: updatedOrder.pk, sk: updatedOrder.sk }, // Key object with both partition and sort key
70+
updatedOrder,
71+
[
72+
{
73+
kind: ConditionExpressionKind.Comparison,
74+
key: 'pk',
75+
comparator: ('attribute_not_exists' as unknown) as FilterOperators,
76+
value: updatedOrder.pk,
77+
},
78+
],
79+
);
80+
}
81+
testConditionalUpdateItem();

0 commit comments

Comments
 (0)