Skip to content

Commit

Permalink
feat(sdk)!: implement missing dynamodb table inflight methods (#4387)
Browse files Browse the repository at this point in the history
- Implements missing options and return types for many inflight functions
- Adds more inflight functions (`batchGetItem` and `batchWriteItem`)

Fixes #4385.

BREAKING CHANGE:

- Refactors all DynamoDBTable inflights to accept one single options parameter
- Refactors some DynamoDBTable inflights to return additional data
- Renames the inflight option types to use "options" as a suffix rather than "props"
  • Loading branch information
skyrpex authored Oct 5, 2023
1 parent 066e142 commit 4603685
Show file tree
Hide file tree
Showing 11 changed files with 2,701 additions and 689 deletions.
7 changes: 4 additions & 3 deletions apps/wing-console/console/server/src/router/dynamodb-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const createDynamodbTableRouter = () => {
const client = simulator.getResource(
input.resourcePath,
) as IDynamodbTableClient;
return await client.getItem(input.key as any);
const { item } = await client.getItem(input.key as any);
return item;
}),
"dynamodb-table.insert": createProcedure
.input(
Expand All @@ -58,7 +59,7 @@ export const createDynamodbTableRouter = () => {
input.resourcePath,
) as IDynamodbTableClient;

await client.putItem(input.data as Json);
await client.putItem({ item: input.data as Json });
}),
"dynamodb-table.delete": createProcedure
.input(
Expand All @@ -82,7 +83,7 @@ export const createDynamodbTableRouter = () => {
? { [schema.props.rangeKey]: input.data[schema.props.rangeKey] }
: {}),
};
return await client.deleteItem(itemKey as Json);
return await client.deleteItem({ key: itemKey as Json });
}),
});
};
2,119 changes: 1,670 additions & 449 deletions docs/docs/04-standard-library/02-ex/dynamodb-table.md

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions examples/tests/sdk_tests/dynamodb-table/query.main.w
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ let t1 = new ex.DynamodbTable(name: "test1", attributeDefinitions: { "k1": "S",

test "query" {
t1.putItem({
"k1": "key1",
"k2": "value1",
"k3": "other-value1"
item: {
"k1": "key1",
"k2": "value1",
"k3": "other-value1"
}
});
t1.putItem({
"k1": "key1",
"k2": "value2",
"k3": "other-value2"
item: {
"k1": "key1",
"k2": "value2",
"k3": "other-value2"
}
});

let result = t1.query(
Expand Down
36 changes: 20 additions & 16 deletions examples/tests/sdk_tests/dynamodb-table/transaction.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ let t1 = new ex.DynamodbTable(name: "test1", attributeDefinitions: { "k1": "S",

test "transactWriteItems" {
t1.putItem({
"k1": "key1",
"k2": "value1",
"k3": "other-value1"
item: {
"k1": "key1",
"k2": "value1",
"k3": "other-value1"
}
});
t1.putItem({
"k1": "key2",
"k2": "value2",
"k3": "other-value2"
item: {
"k1": "key2",
"k2": "value2",
"k3": "other-value2"
}
});

t1.transactWriteItems(transactItems: [
Expand All @@ -44,16 +48,16 @@ test "transactWriteItems" {
}
]);

let var r = t1.getItem({ "k1": "key1", "k2": "value1" });
assert(r.get("k1").asStr() == "key1");
assert(r.get("k2").asStr() == "value1");
assert(r.get("k3").asStr() == "not-other-value1");
let var r = t1.getItem({ key: { "k1": "key1", "k2": "value1" } });
assert(r.item?.get("k1")?.asStr() == "key1");
assert(r.item?.get("k2")?.asStr() == "value1");
assert(r.item?.get("k3")?.asStr() == "not-other-value1");

r = t1.getItem({ "k1": "key2", "k2": "value2" });
assert(r.tryGet("k1") == nil);
r = t1.getItem({ key: { "k1": "key2", "k2": "value2" } });
assert(r.item?.tryGet("k1") == nil);

r = t1.getItem({ "k1": "key3", "k2": "value3" });
assert(r.get("k1").asStr() == "key3");
assert(r.get("k2").asStr() == "value3");
assert(r.get("k3").asStr() == "other-value3");
r = t1.getItem({ key: { "k1": "key3", "k2": "value3" } });
assert(r.item?.get("k1")?.asStr() == "key3");
assert(r.item?.get("k2")?.asStr() == "value3");
assert(r.item?.get("k3")?.asStr() == "other-value3");
}
Loading

0 comments on commit 4603685

Please sign in to comment.