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
Future<(APIResponse, ZCatalystRow)> <ROW_INSTANCE>.update()

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

    
copy
var (response, row) = ZCatalystApp.getInstance() .getDataStoreInstance() .getTableInstance(identifier: 'Products') .getRow(id: 2823000000014176) row.setColumnValue('product_quantity', '100'); //Pass the modified column name and value in the row try { var (response, row) = await row.update(); print('Row updated successfully ${row.getColumnValue('product_quantity')}'); } on ZCatalystException catch (ex) { print('Failed to update the row $exception'); }

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
Future<(APIResponse, List<ZCatalystRow>)> <TABLE_INSTANCE>.updateRows(List<ZCatalystRow> rows)

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 try{ var (_, row) = await table.getRow(id: 2823000000014176); row.setColumnValue('product_price', '400'); modifiedRows.add(row); var (_, row) = await table.getRow(id: 2823000000014177); row.setColumnValue('product_price', '90'); modifiedRows.add(row); var (_, row) = await table.getRow(id: 2823000000014178); row.setColumnValue('product_price', '100'); modifiedRows.add(row); var (response, rows) = await table.updateRows(modifiedRows); } on ZCatalystException catch (ex) { print("Failed to update rows: $ex") }

Last Updated 2024-09-12 18:16:13 +0530 +0530