Utilisez le SDK PHP pour mettre à jour les valeurs des colonnes d'attribut, ajouter des colonnes d'attribut, supprimer une version spécifique d'une colonne d'attribut ou supprimer entièrement une colonne d'attribut dans une table de données Tablestore.
Avant de commencer
Méthode
public function updateRow(array $request)
Exemples
L'exemple suivant met à jour la ligne dont la valeur de clé primaire est row1 dans la table test_table, en définissant la colonne d'attribut col1 sur changed_val1.
$request = array(
'table_name' => 'test_table',
// Build the primary key
'primary_key' => array(
array('id', 'row1')
),
// Specify the update condition when updating a row.
// RowExistenceExpectationConst::CONST_IGNORE means skip row existence checking.
'condition' => RowExistenceExpectationConst::CONST_IGNORE
);
// Attribute columns to update
$request['update_of_attribute_columns'] = array(
'PUT' => array(
array('col1', 'changed_val1')
)
);
try {
// Call the updateRow method to update the row
$response = $client->updateRow($request);
echo "* Read CU Cost: " . $response['consumed']['capacity_unit']['read'] . "\n";
echo "* Write CU Cost: " . $response['consumed']['capacity_unit']['write'] . "\n";
} catch (Exception $e) {
echo "Update Row failed.";
}
Vous pouvez également utiliser les extraits de code suivants pour d'autres opérations de mise à jour.
-
Ajouter une colonne d'attribut.
$request['update_of_attribute_columns'] = array( 'PUT' => array( array('col2', 'val2') ) ); -
Définir le numéro de version pour une colonne d'attribut.
$request['update_of_attribute_columns'] = array( 'PUT' => array( array('col2', 'val2', null, intval(microtime(true) * 1000)) ) ); -
Supprimer une version spécifique d'une colonne d'attribut.
$request['update_of_attribute_columns'] = array( 'DELETE' => array( array('col2', 1754285998447) ) ); -
Supprimer toutes les versions d'une colonne d'attribut.
$request['update_of_attribute_columns'] = array( 'DELETE_ALL' => array('col2') );