Topik ini menjelaskan cara mengambil informasi tabel menggunakan Tablestore SDK untuk Go.
Prasyarat
Klien harus diinisialisasi terlebih dahulu. Untuk detail lebih lanjut, lihat Inisialisasi Klien Tablestore.
Deskripsi metode
func (tableStoreClient *TableStoreClient) DescribeTable(request *DescribeTableRequest) (*DescribeTableResponse, error)Contoh kode
Berikut adalah contoh kode untuk mengambil informasi dari tabel 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("Gagal mendeskripsikan tabel dengan kesalahan:", err)
} else {
// Mendapatkan informasi skema tabel data.
tableMeta := response.TableMeta
fmt.Printf("* Nama tabel: %s \n", tableMeta.TableName)
fmt.Println("* Informasi kunci utama (tipe kunci utama 1:INTEGER,2:STRING,3:BINARY)")
for _, schemaEntry := range tableMeta.SchemaEntry {
fmt.Printf("%s:%v \n", *schemaEntry.Name, *schemaEntry.Type)
}
fmt.Println("* Informasi kolom yang telah ditentukan sebelumnya (tipe kolom yang telah ditentukan sebelumnya 1:INTEGER,2:DOUBLE,3:BOOLEAN,4:STRING,5:BINARY)")
for _, definedColumn := range tableMeta.DefinedColumns {
fmt.Printf("%s:%v \n", definedColumn.Name, definedColumn.ColumnType)
}
// Mendapatkan informasi konfigurasi tabel data.
tableOption := response.TableOption
fmt.Println("* Informasi konfigurasi tabel")
fmt.Printf("Jumlah versi maksimum: %d \n", tableOption.MaxVersion)
fmt.Printf("Waktu hidup: %d \n", tableOption.TimeToAlive)
fmt.Printf("Offset versi maksimum: %d \n", tableOption.DeviationCellVersionInSec)
fmt.Printf("Mengizinkan pembaruan: %t \n", *tableOption.AllowUpdate)
// Mendapatkan informasi Stream tabel.
streamDetails := response.StreamDetails
fmt.Printf("* Apakah Stream diaktifkan: %t \n", streamDetails.EnableStream)
if streamDetails.EnableStream {
fmt.Printf("Waktu kedaluwarsa Stream: %d \n", streamDetails.ExpirationTime)
}
// Mendapatkan pengaturan enkripsi tabel.
sseDetails := response.SSEDetails
fmt.Printf("* Apakah enkripsi tabel diaktifkan: %t \n", sseDetails.Enable)
if sseDetails.Enable {
fmt.Printf("Metode enkripsi: %s \n", sseDetails.KeyType.String())
}
// Mendapatkan throughput baca/tulis yang dicadangkan untuk tabel.
reservedThroughput := response.ReservedThroughput
fmt.Println("* Throughput baca/tulis yang dicadangkan")
fmt.Printf("Throughput baca yang dicadangkan: %d \n", reservedThroughput.Readcap)
fmt.Printf("Throughput tulis yang dicadangkan: %d \n", reservedThroughput.Writecap)
// Mendapatkan informasi indeks sekunder.
indexMetas := response.IndexMetas
for _, indexMeta := range indexMetas {
fmt.Printf("* Nama indeks sekunder: %s \n", indexMeta.IndexName)
fmt.Printf("Kolom kunci utama: %v \n", indexMeta.Primarykey)
fmt.Printf("Kolom yang telah ditentukan sebelumnya: %v \n", indexMeta.DefinedColumns)
fmt.Printf("Tipe indeks sekunder: %d (0:IT_GLOBAL_INDEX,1:IT_LOCAL_INDEX) \n", indexMeta.IndexType)
}
}
}