Skip to content

Commit

Permalink
feat(sdk)!: improve dynamodb table resource (#4242)
Browse files Browse the repository at this point in the history
Adds the DynamoDBTable query command, and changes the scan command as well.

BREAKING CHANGE: the response of the DynamoDBTable scan command now returns an object that contains the items (and other stuff) instead of returning the items directly
  • Loading branch information
skyrpex authored Sep 22, 2023
1 parent 0316314 commit eee94aa
Show file tree
Hide file tree
Showing 10 changed files with 1,264 additions and 30 deletions.
2 changes: 2 additions & 0 deletions apps/wing-console/console/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export type {
LayoutComponentType,
} from "./utils/createRouter.js";

export * from "@winglang/sdk/lib/ex/index.js";

export type RouteNames = keyof inferRouterInputs<Router> | undefined;

export { isTermsAccepted } from "./utils/terms-and-conditions.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const DynamodbTableInteractionView = ({

useEffect(() => {
if (table.data?.rows) {
const rows = table.data.rows.map((row) => {
const rows = table.data.rows.items.map((row) => {
return {
data: row,
error: "",
Expand All @@ -76,16 +76,18 @@ export const DynamodbTableInteractionView = ({
<Attribute name="Name" value={table.data?.name} noLeftPadding />
</div>

<div className="flex items-center gap-2 justify-end">
<DynamodbTableInteraction
rows={rows}
hashKey={table.data?.hashKey}
rangeKey={table.data?.rangeKey}
onAddRow={onAddRow}
onRemoveRow={onRemoveRow}
loading={loading}
/>
</div>
{table.data && (
<div className="flex items-center gap-2 justify-end">
<DynamodbTableInteraction
rows={rows}
hashKey={table.data.hashKey}
rangeKey={table.data.rangeKey}
onAddRow={onAddRow}
onRemoveRow={onRemoveRow}
loading={loading}
/>
</div>
)}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const useDynamodbTable = ({ resourcePath }: UseTableOptions) => {

const removeRow = useCallback(
async (index: number) => {
const row = table.data?.rows[index];
const row = table.data?.rows.items[index];
if (!row) {
return;
}
Expand Down
659 changes: 653 additions & 6 deletions docs/docs/04-standard-library/06-ex/api-reference.md

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions examples/tests/sdk_tests/dynamodb-table/query.main.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*\
skipPlatforms:
- win32
- darwin
\*/

bring ex;

let t1 = new ex.DynamodbTable(name: "test1", attributeDefinitions: { "k1": "S", "k2": "S" }, hashKey: "k1", rangeKey: "k2");

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

let result = t1.query(
keyConditionExpression: "k1 = :k1",
expressionAttributeValues: {
":k1": "key1",
},
);

assert(result.count == 2);
assert(result.items.at(0).get("k1") == "key1");
assert(result.items.at(0).get("k2") == "value1");
assert(result.items.at(0).get("k3") == "other-value1");
assert(result.items.at(1).get("k1") == "key1");
assert(result.items.at(1).get("k2") == "value2");
assert(result.items.at(1).get("k3") == "other-value2");
}
Loading

0 comments on commit eee94aa

Please sign in to comment.