diff --git a/dynamo.js b/dynamo.js index eb21541..43c2ac4 100644 --- a/dynamo.js +++ b/dynamo.js @@ -4,12 +4,12 @@ const client = new DynamoDBClient({}); // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/PutItemCommand/ export async function _putItem(tableName, item) { - const command = new PutItemCommand({ + const putItemInput = { TableName: tableName, Item: item, - }); - console.log(command); - + }; + console.log(putItemInput); + const command = new PutItemCommand(putItemInput); const response = await client.send(command); console.log(response); return response; @@ -17,11 +17,12 @@ export async function _putItem(tableName, item) { // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/GetItemCommand/ export async function _getItem(tableName, key) { - const command = new GetItemCommand({ + const getItemInput = { TableName: tableName, Key: key, - }); - console.log(command); + }; + console.log(getItemInput); + const command = new GetItemCommand(getItemInput); const response = await client.send(command); console.log(response); @@ -33,10 +34,11 @@ export async function _getItem(tableName, key) { // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/ScanCommand/ export async function _scan(tableName) { - const command = new ScanCommand({ + const scanInput = { TableName: tableName, - }); - console.log(command); + }; + console.log(scanInput); + const command = new ScanCommand(scanInput); const response = await client.send(command); console.log(response); diff --git a/dynamodb.w b/dynamodb.w index 5e2af69..783b9d4 100644 --- a/dynamodb.w +++ b/dynamodb.w @@ -93,7 +93,7 @@ pub class DynamoDBTableAws { } extern "./dynamo.js" static inflight _putItem(tableName: str, item: Json): void; - extern "./dynamo.js" static inflight _getItem(tableName: str, key: Json): Map>>; + extern "./dynamo.js" static inflight _getItem(tableName: str, key: Json): Map>>?; extern "./dynamo.js" static inflight _scan(tableName: str): Map>>>; pub inflight putItem(item: Map) { @@ -104,7 +104,7 @@ pub class DynamoDBTableAws { pub inflight getItem(key: Map): Map { let json = this._itemToJson(key); let result = DynamoDBTableAws._getItem(this.tableName, json); - return this._rawMapToItem(result.get("Item")); + return this._rawMapToItem(result?.get("Item") ?? {}); } pub inflight scan(): Array> {