diff --git a/readme.md b/readme.md index 91183a7..4f19e60 100644 --- a/readme.md +++ b/readme.md @@ -41,9 +41,9 @@ cmake --install . --config=Release ### Download the latest release ```bash -wget https://github.com/jerily/aws-sdk-tcl/archive/refs/tags/v1.0.9.tar.gz -tar -xzf v1.0.9.tar.gz -export TCL_AWS_DIR=$(pwd)/aws-sdk-tcl-1.0.9 +wget https://github.com/jerily/aws-sdk-tcl/archive/refs/tags/v1.0.10.tar.gz +tar -xzf v1.0.10.tar.gz +export TCL_AWS_DIR=$(pwd)/aws-sdk-tcl-1.0.10 ``` ### Build for TCL: diff --git a/src/aws-sdk-tcl-dynamodb/CMakeLists.txt b/src/aws-sdk-tcl-dynamodb/CMakeLists.txt index 82bfb5c..3602dde 100644 --- a/src/aws-sdk-tcl-dynamodb/CMakeLists.txt +++ b/src/aws-sdk-tcl-dynamodb/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22.1) -project(aws-sdk-tcl-dynamodb VERSION 1.0.9 LANGUAGES CXX C) +project(aws-sdk-tcl-dynamodb VERSION 1.0.10 LANGUAGES CXX C) message(project: ${PROJECT_NAME}) set(TARGET ${PROJECT_NAME}) diff --git a/src/aws-sdk-tcl-dynamodb/examples/delete-item.tcl b/src/aws-sdk-tcl-dynamodb/examples/delete-item.tcl new file mode 100644 index 0000000..cf17058 --- /dev/null +++ b/src/aws-sdk-tcl-dynamodb/examples/delete-item.tcl @@ -0,0 +1,58 @@ +package require awsdynamodb + +set table "MyTableWithItems" + +# To use it with real AWS S3, you can use the following configuration: +# set config_dict [dict create region "us-east-1" aws_access_key_id "your_access_key_id" aws_secret_access_key "your_secret_access_key"] + +# To use it with localstack, you can use the following configuration: +set config_dict [dict create region us-east-1 endpoint "http://localhost:4566"] + +# creates a DynamoDB client +::aws::dynamodb::create $config_dict client + +# create a new table with an id attribute of type N (number) and HASH key type +$client create_table $table [dict create id [list N HASH]] + +# an item with a nested structure, it includes the following attributes: +# - id: number +# - name: string +# - age: number +# - scopes: list of strings +# - address: map with the following attributes: +# - street: string +# - city: string +# - state: string +# - zip: number +set item_dict [dict create \ + id [list N 1] \ + name [list S "test"] \ + age [list N 20] \ + scopes [list L [list [list S "read"] [list S "write"] [list S "admin"]]] \ + address [list M [list \ + street [list S "1234 Main Street"] \ + city [list S "Seattle"] \ + state [list S "WA"] \ + zip [list N 98101] \ + ]] \ +] + +# put the item into the table +$client put_item $table $item_dict + +# put a second item into the table +$client put_item $table [dict create id [list N 2] name [list S "test2"]] + +# specify the key of the item to get +set key_dict [dict create id [list N "1"]] + +# delete the item from the table +puts deleted=[$client delete_item $table $key_dict] + +# get the item from the table +set item [$client get_item $table $key_dict] +if { $item eq {} } { + puts "Item not found" +} else { + puts "Item: $item" +} diff --git a/src/aws-sdk-tcl-dynamodb/examples/readme.md b/src/aws-sdk-tcl-dynamodb/examples/readme.md index 476643e..ff37ca8 100644 --- a/src/aws-sdk-tcl-dynamodb/examples/readme.md +++ b/src/aws-sdk-tcl-dynamodb/examples/readme.md @@ -6,5 +6,6 @@ This directory contains examples of using the AWS DynamoDB service with the AWS * [Delete a Table](delete-table.tcl) - Delete a table in DynamoDB. * [List Tables](list-tables.tcl) - List tables in DynamoDB. * [Put and Get Item](put-and-get-item.tcl) - Put an item in a table in DynamoDB. +* [Delete Item](delete-item.tcl) - Delete an item from a table in DynamoDB. * [Query](query.tcl) - Query a table in DynamoDB. * [Global Secondary Index](global-secondary-index.tcl) - Create a global secondary index on a table in DynamoDB. \ No newline at end of file diff --git a/src/aws-sdk-tcl-dynamodb/library.cc b/src/aws-sdk-tcl-dynamodb/library.cc index 31990e9..e8ff2c8 100644 --- a/src/aws-sdk-tcl-dynamodb/library.cc +++ b/src/aws-sdk-tcl-dynamodb/library.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -371,6 +372,53 @@ int aws_sdk_tcl_dynamodb_GetItem(Tcl_Interp *interp, const char *handle, const c } } +int aws_sdk_tcl_dynamodb_DeleteItem(Tcl_Interp *interp, const char *handle, const char *tableName, Tcl_Obj *dictPtr) { + DBG(fprintf(stderr, "aws_sdk_tcl_dynamodb_DeleteItem: handle=%s tableName=%s dict=%s\n", handle, tableName, + Tcl_GetString(dictPtr))); + Aws::DynamoDB::DynamoDBClient *client = aws_sdk_tcl_dynamodb_GetInternalFromName(handle); + if (!client) { + Tcl_SetObjResult(interp, Tcl_NewStringObj("handle not found", -1)); + return TCL_ERROR; + } + + Aws::DynamoDB::Model::DeleteItemRequest deleteItemRequest; + deleteItemRequest.SetTableName(tableName); + + Tcl_DictSearch search; + Tcl_Obj *key, *spec; + int done; + if (Tcl_DictObjFirst(interp, dictPtr, &search, + &key, &spec, &done) != TCL_OK) { + return TCL_ERROR; + } + for (; !done; Tcl_DictObjNext(&search, &key, &spec, &done)) { + Tcl_Size length; + Tcl_ListObjLength(interp, spec, &length); + if (length != 2) { + Tcl_SetObjResult(interp, Tcl_NewStringObj("Invalid attribute value", -1)); + return TCL_ERROR; + } + Aws::String attribute_key = Tcl_GetString(key); + DBG(fprintf(stderr, "key=%s spec=%s\n", attribute_key.c_str(), Tcl_GetString(spec))); + auto value = set_attribute_value(interp, spec); + DBG(fprintf(stderr, "done\n")); + deleteItemRequest.AddKey(attribute_key, *value); + } + Tcl_DictObjDone(&search); + + DBG(fprintf(stderr, "deleteItemRequest ready\n")); + + const Aws::DynamoDB::Model::DeleteItemOutcome outcome = client->DeleteItem( + deleteItemRequest); + if (outcome.IsSuccess()) { + Tcl_SetObjResult(interp, Tcl_NewBooleanObj(1)); + return TCL_OK; + } else { + Tcl_SetObjResult(interp, Tcl_NewStringObj(outcome.GetError().GetMessage().c_str(), -1)); + return TCL_ERROR; + } +} + int aws_sdk_tcl_dynamodb_QueryItems( Tcl_Interp *interp, const char *handle, @@ -917,10 +965,10 @@ int aws_sdk_tcl_dynamodb_ClientObjCmd(ClientData clientData, Tcl_Interp *interp, "destroy", "put_item", "get_item", + "delete_item", "query_items", "scan", "update_item", - "delete_item", "create_table", "delete_table", "list_tables", @@ -931,10 +979,10 @@ int aws_sdk_tcl_dynamodb_ClientObjCmd(ClientData clientData, Tcl_Interp *interp, m_destroy, m_putItem, m_getItem, + m_deleteItem, m_queryItems, m_scan, m_updateItem, - m_deleteItem, m_createTable, m_deleteTable, m_listTables @@ -970,6 +1018,14 @@ int aws_sdk_tcl_dynamodb_ClientObjCmd(ClientData clientData, Tcl_Interp *interp, Tcl_GetString(objv[2]), objv[3] ); + case m_deleteItem: + CheckArgs(4, 4, 1, "delete_item table key_dict"); + return aws_sdk_tcl_dynamodb_DeleteItem( + interp, + handle, + Tcl_GetString(objv[2]), + objv[3] + ); case m_queryItems: CheckArgs(4, 8, 1, "get_item table query_dict ?projection_expression? ?scan_forward? ?limit? ?index_name?"); @@ -993,8 +1049,6 @@ int aws_sdk_tcl_dynamodb_ClientObjCmd(ClientData clientData, Tcl_Interp *interp, ); case m_updateItem: break; - case m_deleteItem: - break; case m_createTable: CheckArgs(4, 6, 1, "create_table table key_schema_dict ?provisioned_throughput_dict? ?global_secondary_indexes_list?"); @@ -1120,6 +1174,12 @@ static int aws_sdk_tcl_dynamodb_GetItemCmd(ClientData clientData, Tcl_Interp *in return aws_sdk_tcl_dynamodb_GetItem(interp, Tcl_GetString(objv[1]), Tcl_GetString(objv[2]), objv[3]); } +static int aws_sdk_tcl_dynamodb_DeleteItemCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { + DBG(fprintf(stderr, "DeleteItemCmd\n")); + CheckArgs(4, 4, 1, "handle_name table key_dict"); + return aws_sdk_tcl_dynamodb_DeleteItem(interp, Tcl_GetString(objv[1]), Tcl_GetString(objv[2]), objv[3]); +} + static int aws_sdk_tcl_dynamodb_QueryItemsCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { DBG(fprintf(stderr, "QueryItemsCmd\n")); @@ -1225,6 +1285,7 @@ int Aws_sdk_tcl_dynamodb_Init(Tcl_Interp *interp) { Tcl_CreateObjCommand(interp, "::aws::dynamodb::destroy", aws_sdk_tcl_dynamodb_DestroyCmd, nullptr, nullptr); Tcl_CreateObjCommand(interp, "::aws::dynamodb::put_item", aws_sdk_tcl_dynamodb_PutItemCmd, nullptr, nullptr); Tcl_CreateObjCommand(interp, "::aws::dynamodb::get_item", aws_sdk_tcl_dynamodb_GetItemCmd, nullptr, nullptr); + Tcl_CreateObjCommand(interp, "::aws::dynamodb::delete_item", aws_sdk_tcl_dynamodb_DeleteItemCmd, nullptr, nullptr); Tcl_CreateObjCommand(interp, "::aws::dynamodb::query_items", aws_sdk_tcl_dynamodb_QueryItemsCmd, nullptr, nullptr); Tcl_CreateObjCommand(interp, "::aws::dynamodb::scan", aws_sdk_tcl_dynamodb_ScanCmd, nullptr, nullptr); Tcl_CreateObjCommand(interp, "::aws::dynamodb::create_table", aws_sdk_tcl_dynamodb_CreateTableCmd, nullptr, diff --git a/src/aws-sdk-tcl-dynamodb/readme.md b/src/aws-sdk-tcl-dynamodb/readme.md index 69c4e2f..5e081ed 100644 --- a/src/aws-sdk-tcl-dynamodb/readme.md +++ b/src/aws-sdk-tcl-dynamodb/readme.md @@ -14,6 +14,8 @@ See the [examples](examples) directory for examples of using the AWS DynamoDB se - puts an item into a table * **::aws::dynamodb::get_item** *handle table key_dict* - gets an item from a table +* **::aws::dynamodb::delete_item** *handle table key_dict* + - deletes an item from a table * **::aws::dynamodb::query_items** *handle table query_dict ?projection_expression? ?scan_forward? ?limit? ?index_name?* - queries items from a table * **::aws::dynamodb::scan** *handle table ?projection_expression?* diff --git a/src/aws-sdk-tcl-iam/CMakeLists.txt b/src/aws-sdk-tcl-iam/CMakeLists.txt index c61e264..5a2d1e0 100644 --- a/src/aws-sdk-tcl-iam/CMakeLists.txt +++ b/src/aws-sdk-tcl-iam/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22.1) -project(aws-sdk-tcl-iam VERSION 1.0.9 LANGUAGES CXX C) +project(aws-sdk-tcl-iam VERSION 1.0.10 LANGUAGES CXX C) message(project: ${PROJECT_NAME}) set(TARGET ${PROJECT_NAME}) diff --git a/src/aws-sdk-tcl-kms/CMakeLists.txt b/src/aws-sdk-tcl-kms/CMakeLists.txt index 271d58b..de17ed4 100644 --- a/src/aws-sdk-tcl-kms/CMakeLists.txt +++ b/src/aws-sdk-tcl-kms/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22.1) -project(aws-sdk-tcl-kms VERSION 1.0.9 LANGUAGES CXX C) +project(aws-sdk-tcl-kms VERSION 1.0.10 LANGUAGES CXX C) message(project: ${PROJECT_NAME}) set(TARGET ${PROJECT_NAME}) diff --git a/src/aws-sdk-tcl-lambda/CMakeLists.txt b/src/aws-sdk-tcl-lambda/CMakeLists.txt index ba61a90..398fe40 100644 --- a/src/aws-sdk-tcl-lambda/CMakeLists.txt +++ b/src/aws-sdk-tcl-lambda/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22.1) -project(aws-sdk-tcl-lambda VERSION 1.0.9 LANGUAGES CXX C) +project(aws-sdk-tcl-lambda VERSION 1.0.10 LANGUAGES CXX C) message(project: ${PROJECT_NAME}) set(TARGET ${PROJECT_NAME}) diff --git a/src/aws-sdk-tcl-s3/CMakeLists.txt b/src/aws-sdk-tcl-s3/CMakeLists.txt index fe40bff..8bd8199 100644 --- a/src/aws-sdk-tcl-s3/CMakeLists.txt +++ b/src/aws-sdk-tcl-s3/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22.1) -project(aws-sdk-tcl-s3 VERSION 1.0.9 LANGUAGES CXX C) +project(aws-sdk-tcl-s3 VERSION 1.0.10 LANGUAGES CXX C) message(project: ${PROJECT_NAME}) set(TARGET ${PROJECT_NAME}) diff --git a/src/aws-sdk-tcl-sqs/CMakeLists.txt b/src/aws-sdk-tcl-sqs/CMakeLists.txt index 0ef1c9a..8285fc6 100644 --- a/src/aws-sdk-tcl-sqs/CMakeLists.txt +++ b/src/aws-sdk-tcl-sqs/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22.1) -project(aws-sdk-tcl-sqs VERSION 1.0.9 LANGUAGES CXX C) +project(aws-sdk-tcl-sqs VERSION 1.0.10 LANGUAGES CXX C) message(project: ${PROJECT_NAME}) set(TARGET ${PROJECT_NAME}) diff --git a/src/aws-sdk-tcl-ssm/CMakeLists.txt b/src/aws-sdk-tcl-ssm/CMakeLists.txt index e81f8d6..9946e72 100644 --- a/src/aws-sdk-tcl-ssm/CMakeLists.txt +++ b/src/aws-sdk-tcl-ssm/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22.1) -project(aws-sdk-tcl-ssm VERSION 1.0.9 LANGUAGES CXX C) +project(aws-sdk-tcl-ssm VERSION 1.0.10 LANGUAGES CXX C) message(project: ${PROJECT_NAME}) set(TARGET ${PROJECT_NAME}) diff --git a/ttrek.json b/ttrek.json index 5225eb3..26a3f46 100644 --- a/ttrek.json +++ b/ttrek.json @@ -1,6 +1,6 @@ { "name": "aws-sdk-tcl", - "version": "1.0.9", + "version": "1.0.10", "scripts": { }, @@ -15,7 +15,7 @@ "default": [ { "cmd": "download", - "url": "https://github.com/jerily/aws-sdk-tcl/archive/refs/tags/v1.0.9.tar.gz" + "url": "https://github.com/jerily/aws-sdk-tcl/archive/refs/tags/v1.0.10.tar.gz" }, { "cmd": "unpack"