Update Rows

Update a Specific Row

You can update a single specific row in a Data Store table using the update() method after fetching the row instance. This enables you to update the values of one or more columns of the row by passing the modified values of the columns as key-value pairs to the setColumnValue() method.

The <ROW_INSTANCE> used in the code syntax below is the instance defined in the Row Instance page.

    
copy
<ROW_INSTANCE>.update( void Function(ZCatalystRow) onSuccess, void Function(ZCatalystException) onFailed )

A sample code snippet with fetching the row instance is shown below:

    
copy
ZCatalystApp.getInstance() .getDataStoreInstance() .getTableInstance(identifier: 'Products') .getRow( id: 2823000000014176, //Fetch the row instance onSuccess: (APIResponse response, ZCatalystRow row) { row.setColumnValue('product_quantity', '100'); //Pass the modified column name and value in the row row.update( //Update the row onSuccess: (APIResponse response, ZCatalystRow row) { print( 'Row updated successfully ${row.getColumnValue('product_quantity')}'); //Actions to be executed upon a succesful update }, onFailed: (ZCatalystException exception) { print('Failed to update the row $exception'); //Actions to be executed upon a failed updated }, ); }, onFailed: (ZCatalystException exception) { print('Get Row Failed: $exception'); //Actions to be executed upon failure in fetching the row instance }, );

Update all Rows

You can update multiple row in a table by passing a list of the rows as an argument to the updateRows() method. You must fetch the row instances for each column key-value pair to be updated in a row and pass the modified data through the setColumnValue() method. You can then add the row instances to an array and passing the array as an argument to the updateRows() method, as shown in the code syntax below.

The <TABLE_INSTANCE> used in the code below is the instance defined in the Table Instance page.

    
copy
<TABLE_INSTANCE>.updateRows( List<ZCatalystRow> rows, void Function(List<ZCatalystRow>) onSuccess, void Function(ZCatalystException) onFailed )

Parameters:

  • rows: The list of rows to be updated

A sample code snippet with fetching the row instance is shown below:

    
copy
List<ZCatalystRow> modifiedRows = []; //Create an array var table = ZCatalystApp.getInstance() .getDataStoreInstance() .getTableInstance(identifier: 'Products'); //Create table instance await table.getRow( //Fetch row instance for a row to be updated id: 2823000000014176, onSuccess: (APIResponse response, ZCatalystRow row) { row.setColumnValue('product_price', '400'); //Pass the column name-value to be updated modifiedRows.add(row); //Add the row instance to the array }, onFailed: (ZCatalystException exception) { print('Get Row Failed: $exception'); }, ); await table.getRow( id: 2823000000014177, onSuccess: (APIResponse response, ZCatalystRow row) { row.setColumnValue('product_price', '90'); modifiedRows.add(row); }, onFailed: (ZCatalystException exception) { print('Get Row Failed: $exception'); }, ); await table.getRow( id: 2823000000014178, onSuccess: (APIResponse response, ZCatalystRow row) { row.setColumnValue('product_price', '100'); modifiedRows.add(row); }, onFailed: (ZCatalystException exception) { print('Get Row Failed: $exception'); }, ); //Pass the array containing the row instances to the updateRows() method table.updateRows( rows: modifiedRows, onSuccess: (APIResponse response, List<ZCatalystRow> rows) { print('The rows are updated successfully: $rows'); }, //Actions to be executed upon a successful update onFailed: (ZCatalystException exception) { print('Exception thrown: $exception'); //Actions to be handled upon a failed state }, );

Last Updated 2023-09-03 01:06:41 +0530 +0530