///<summary>/// Updates the movie table to add a boolean column named watched.///</summary>///<param name="keyspaceName">The keyspace containing the table.</param>///<param name="tableName">The name of the table to change.</param>///<returns>The Amazon Resource Name (ARN) of the updated table.</returns>publicasync Task<string> UpdateTable(string keyspaceName, string tableName){var newColumn = new ColumnDefinition { Name = "watched", Type = "boolean" };
var request = new UpdateTableRequest
{
KeyspaceName = keyspaceName,
TableName = tableName,
AddColumns = new List<ColumnDefinition> { newColumn }
};
var response = await _amazonKeyspaces.UpdateTableAsync(request);
return response.ResourceArn;
}
如需 API 詳細資訊,請參閱AWS SDK for .NET 《 API 參考》中的 UpdateTable。
classKeyspaceWrapper:"""Encapsulates Amazon Keyspaces (for Apache Cassandra) keyspace and table actions."""def__init__(self, keyspaces_client):"""
:param keyspaces_client: A Boto3 Amazon Keyspaces client.
"""
self.keyspaces_client = keyspaces_client
self.ks_name = None
self.ks_arn = None
self.table_name = None @classmethoddeffrom_client(cls):
keyspaces_client = boto3.client("keyspaces")
return cls(keyspaces_client)
defupdate_table(self):"""
Updates the schema of the table.
This example updates a table of movie data by adding a new column
that tracks whether the movie has been watched.
"""try:
self.keyspaces_client.update_table(
keyspaceName=self.ks_name,
tableName=self.table_name,
addColumns=[{"name": "watched", "type": "boolean"}],
)
except ClientError as err:
logger.error(
"Couldn't update table %s. Here's why: %s: %s",
self.table_name,
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raise
如需 API 詳細資訊,請參閱《適用於 AWS Python (Boto3) 的 SDK API 參考》中的 UpdateTable。
///<summary>/// Updates the movie table to add a boolean column named watched.///</summary>///<param name="keyspaceName">The keyspace containing the table.</param>///<param name="tableName">The name of the table to change.</param>///<returns>The Amazon Resource Name (ARN) of the updated table.</returns>publicasync Task<string> UpdateTable(string keyspaceName, string tableName){var newColumn = new ColumnDefinition { Name = "watched", Type = "boolean" };
var request = new UpdateTableRequest
{
KeyspaceName = keyspaceName,
TableName = tableName,
AddColumns = new List<ColumnDefinition> { newColumn }
};
var response = await _amazonKeyspaces.UpdateTableAsync(request);
return response.ResourceArn;
}
如需 API 詳細資訊,請參閱AWS SDK for .NET 《 API 參考》中的 UpdateTable。