Use the Tablestore SDK for Go to read a row from a Wide Column model table by specifying its complete primary key.
Prerequisites
Install the Tablestore SDK for Go and initialize the client.
Description
Call GetRow to read a row by specifying its complete primary key. You can limit the returned attribute columns, data versions, and version time range, or use a filter to screen attribute columns.
func (tableStoreClient *TableStoreClient) GetRow(request *GetRowRequest) (*GetRowResponse, error)
The following sample reads the row whose primary key value is row1 from the example_table table.
primaryKey := &tablestore.PrimaryKey{}
primaryKey.AddPrimaryKeyColumn("id", "row1")
request := &tablestore.GetRowRequest{
SingleRowQueryCriteria: &tablestore.SingleRowQueryCriteria{
TableName: "example_table",
PrimaryKey: primaryKey,
MaxVersion: 1,
},
}
response, err := client.GetRow(request)
if err != nil {
log.Fatal(err)
}
fmt.Println(response.PrimaryKey)
fmt.Println(response.Columns)
Parameters
GetRowRequest contains the following parameter.
|
Name |
Type |
Description |
|
SingleRowQueryCriteria (required) |
|
The row query criteria. |
Row query criteria
SingleRowQueryCriteria contains the following parameters.
|
Name |
Type |
Description |
|
TableName (required) |
|
The table name. |
|
PrimaryKey (required) |
|
The complete primary key of the row. To read a row that contains an auto-increment primary key column, also specify the actual auto-increment value. |
|
MaxVersion (optional) |
|
The maximum number of versions to return. At least one of |
|
TimeRange (optional) |
|
The version time range, which specifies a start time, end time, or exact version in milliseconds. At least one of |
|
ColumnsToGet (optional) |
|
The attribute columns to return. If this parameter is not specified, all attribute columns are returned. If both |
|
Filter (optional) |
|
The attribute column filter. For more information, see Use filters. |
|
StartColumn (optional) |
|
The start attribute column of the name range. This column is included in the result. |
|
EndColumn (optional) |
|
The end attribute column of the name range. This column is excluded from the result. |
|
TransactionId (optional) |
|
The local transaction ID. Specify this parameter only for a read in a local transaction. For more information, see Use local transactions. |
Response
GetRowResponse contains the following business information. If the row does not exist, the response does not contain a primary key or attribute columns.
|
Field |
Type |
Description |
|
|
|
The primary key of the row. |
|
|
|
The returned attribute columns, values, and versions. |
Examples
Read data versions in a time range
The following sample reads data versions generated within the previous day.
now := time.Now().UnixMilli()
request.SingleRowQueryCriteria.MaxVersion = 0
request.SingleRowQueryCriteria.TimeRange = &tablestore.TimeRange{
Start: now - 24*60*60*1000,
End: now,
}