本文介紹如何通過 Go SDK 更新表的配置資訊。
前提條件
方法說明
func (tableStoreClient *TableStoreClient) UpdateTable(request *UpdateTableRequest) (*UpdateTableResponse, error)
說明
調用
UpdateTable()
方法時,必須設定TableOption、StreamSpec、ReservedThroughput中的至少一項。設定 TableOption 時,必須設定 TimeToAlive 和 MaxVersion 參數。
範例程式碼
以下範例程式碼用於修改test_table表的配置資訊。
func UpdateTableSample(client *tablestore.TableStoreClient) {
updateTableReq := new(tablestore.UpdateTableRequest)
updateTableReq.TableName = "test_table"
// 表配置資訊
updateTableReq.TableOption = new(tablestore.TableOption)
// 設定資料生命週期,單位為秒
updateTableReq.TableOption.TimeToAlive = 86400
// 設定最大版本數
updateTableReq.TableOption.MaxVersion = 3
// 設定有效版本偏差,單位為秒
updateTableReq.TableOption.DeviationCellVersionInSec = 86400
// 設定是否允許更新
updateTableReq.TableOption.AllowUpdate = proto.Bool(false)
// 開啟Stream資訊,並設定Stream到期時間為7天
updateTableReq.StreamSpec = new(tablestore.StreamSpecification)
updateTableReq.StreamSpec.EnableStream = true
updateTableReq.StreamSpec.ExpirationTime = 168
// 設定預留讀為0CU,預留寫為0CU(僅CU模式高效能執行個體支援設定資料表的預留讀寫輸送量為非零值)
updateTableReq.ReservedThroughput = new(tablestore.ReservedThroughput)
updateTableReq.ReservedThroughput.Readcap = 0
updateTableReq.ReservedThroughput.Writecap = 0
// 調用UpdateTable方法修改表配置
_, err := client.UpdateTable(updateTableReq)
if (err != nil) {
fmt.Println("Failed to update table with error:", err)
} else {
fmt.Println("Update table finished.")
}
}