Update Rows

Update a Specific Row

You can update a single specific row in a Data Store table using the update() method. 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.

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

    
copy
<ROW_INSTANCE>.update( completion: @escaping(Result<ZCatalystRow, ZCatalystError>) -> Void)

Parameters:

  • completion: If the operation is successful, the completion block will return the details of the updated row. Else, it will return an error.

A sample code snippet is shown below:

    
copy
ZCatalystApp.shared.getDataStoreInstance(tableIdentifier: "1096000000002071").getRow(id: 3376000000170191){(result)in //Replace this with your Table ID switch result{ case .success ( let row) : row.setColumnValue(columnName: "Employee_Name", value: "Morgan Jones") //replace your column name and value here row.update {(update_result) in switch update_result{ case .success(let updated_row) : print("Name is updated") case .error( let error ) : print( "Error occurred >>> \( error )" ) } } case .error( let error ) : print( "Error occurred >>> \( error )" ) } }

Update all Rows

You can update multiple row in a table by passing an array of the rows as an argument to the update() method. This enables you to update the values of one or more columns of the rows, by passing the modified values of the columns as key-value pairs.

You must pass the array of the row instances to be updated by creating the instance for each row, and passing the updated value of each corresponding column using the Add Column Value method, as shown in the code below.

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

    
copy
<DATA_STORE_INSTANCE>.update(_ rows: [ ZCatalystRow ], completion: @escaping(Result<[ZCatalystRow], ZCatalystError>) -> Void)

Parameters:

  • rows: The array of rows to be updated
  • completion: If the operation is successful, the completion block will return the details of all the updated rows. Else, it will return an error.

A sample code snippet is shown below:

    
copy
let data_store_instance = ZCatalystApp.shared.getDataStoreInstance(tableIdentifier: "EmployeeDetails")//Replace this with you Table Name data_store_instance.getRows{(result)in switch result{ case .success ( let rows) : for row in rows{ row.setColumnValue(columnName: "Employee_Name", value: "Morgan Jones") } data_store_instance.update(rows) {(result) in switch result { case .success ( let updated_rows): print("Rows has been successfully updated"); case .error( let error ) : print( "Error occurred >>> \( error )" ) } } case .error(let error): print("Error occurred >>> \( error )") } }

Last Updated 2023-09-14 18:05:46 +0530 +0530