Use the Tablestore SDK for Go to delete a row identified by its primary key from a Wide Column model table.
Prerequisites
Install the Tablestore SDK for Go and initialize the client.
Description
Call DeleteRow to delete a row identified by its primary key. You can use Condition to control whether the deletion is performed.
func (tableStoreClient *TableStoreClient) DeleteRow(request *DeleteRowRequest) (*DeleteRowResponse, error)
The following sample deletes the row whose primary key value is row1 from the example_table table.
primaryKey := &tablestore.PrimaryKey{}
primaryKey.AddPrimaryKeyColumn("id", "row1")
change := &tablestore.DeleteRowChange{
TableName: "example_table",
PrimaryKey: primaryKey,
}
change.SetCondition(tablestore.RowExistenceExpectation_EXPECT_EXIST)
_, err := client.DeleteRow(&tablestore.DeleteRowRequest{DeleteRowChange: change})
if err != nil {
log.Fatal(err)
}
Parameters
DeleteRowRequest contains the following parameter.
|
Name |
Type |
Description |
|
DeleteRowChange (required) |
|
The row deletion configuration. |
Row change
DeleteRowChange contains the following parameters.
|
Name |
Type |
Description |
|
TableName (required) |
|
The table name. |
|
PrimaryKey (required) |
|
The primary key of the row. The names, order, and types of the primary key columns must match the table schema. |
|
Condition (required) |
|
The deletion condition, which can include a row existence condition and a column condition. For more information, see Use conditional updates. |
|
TransactionId (optional) |
|
The local transaction ID. Specify this parameter only for a deletion in a local transaction. For more information, see Use local transactions. |