本文介紹如何通過Go SDK查詢資料表的詳細資料。
前提條件
方法說明
func (tableStoreClient *TableStoreClient) DescribeTable(request *DescribeTableRequest) (*DescribeTableResponse, error)範例程式碼
以下範例程式碼用於查詢test_table表的詳細資料。
func DescribeTableSample(client *tablestore.TableStoreClient) {
describeTableReq := new(tablestore.DescribeTableRequest)
describeTableReq.TableName = "test_table"
response, err := client.DescribeTable(describeTableReq)
if err != nil {
fmt.Println("Failed to describe table with error:", err)
} else {
// 擷取資料表結構資訊
tableMeta := response.TableMeta
fmt.Printf("* 資料表名稱: %s \n", tableMeta.TableName)
fmt.Println("* 主鍵資訊 (主鍵類型 1:INTEGER,2:STRING,3:BINARY)")
for _, schemaEntry := range tableMeta.SchemaEntry {
fmt.Printf("%s:%v \n", *schemaEntry.Name, *schemaEntry.Type)
}
fmt.Println("* 預定義列資訊 (預定義列類型 1:INTEGER,2:DOUBLE,3:BOOLEAN,4:STRING,5:BINARY)")
for _, definedColumn := range tableMeta.DefinedColumns {
fmt.Printf("%s:%v \n", definedColumn.Name, definedColumn.ColumnType)
}
// 擷取資料表的配置資訊
tableOption := response.TableOption
fmt.Println("* 資料表配置資訊")
fmt.Printf("最大版本數: %d \n", tableOption.MaxVersion)
fmt.Printf("資料生命週期: %d \n", tableOption.TimeToAlive)
fmt.Printf("有效版本偏差: %d \n", tableOption.DeviationCellVersionInSec)
fmt.Printf("是否允許更新: %t \n", *tableOption.AllowUpdate)
// 擷取資料表Stream資訊
streamDetails := response.StreamDetails
fmt.Printf("* 是否開啟Steam: %t \n", streamDetails.EnableStream)
if streamDetails.EnableStream {
fmt.Printf("Stream到期時間: %d \n", streamDetails.ExpirationTime)
}
// 擷取資料表加密設定
sseDetails := response.SSEDetails
fmt.Printf("* 是否開啟資料表加密: %t \n", sseDetails.Enable)
if sseDetails.Enable {
fmt.Printf("加密方式: %s \n", sseDetails.KeyType.String())
}
// 擷取資料表預留讀寫輸送量
reservedThroughput := response.ReservedThroughput
fmt.Println("* 預留讀寫輸送量")
fmt.Printf("預留讀輸送量: %d \n", reservedThroughput.Readcap)
fmt.Printf("預留寫輸送量: %d \n", reservedThroughput.Writecap)
// 擷取二級索引資訊
indexMetas := response.IndexMetas
for _, indexMeta := range indexMetas {
fmt.Printf("* 二級索引名稱: %s \n", indexMeta.IndexName)
fmt.Printf("主鍵列表: %v \n", indexMeta.Primarykey)
fmt.Printf("預定義列列表: %v \n", indexMeta.DefinedColumns)
fmt.Printf("二級索引類型: %d (0:IT_GLOBAL_INDEX,1:IT_LOCAL_INDEX) \n", indexMeta.IndexType)
}
}
}