Update Rows

You can update a single row or multiple rows in a table in the Catalyst Data Store. The table_service reference used in the below code snippets can either be a table instance or table meta created earlier.

Update a Single Row

This particular method allows you to update a single row by constructing an object with modified values in the required columns.

Refer the unique ROWID and pass the newly constructed object that contains the updated row details to the update_row() method. Please note that it is mandatory to specify the ROWID value here. The datastore_service reference used below is already defined in the component instance page.

    
copy
#Update a single row table_service = datastore_service.table("table_name") row_data = {'name': 'Mathew Jones', 'id': '7211', 'age': '31', 'ROWID': 2136000000011011} row_response = table_service.update_row(row_data) logging.info(row_response)

A sample response is shown below :

    
copy
{ CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-17 13:02:11:184", CREATEDTIME: "2021-08-16 16:29:10:499", Name: "Mathew Jones", ID : "7211", Age: 31, ROWID: "2136000000011011" }

Update Multiple Rows

To update multiple rows, an array of objects is constructed containing the modified row values, which is passed as an argument to the update_rows() method. The ROWIDs are used in corresponding array objects to refer the specific rows which requires modification. The datastore_service reference used below is already defined in the component instance page.

The response returned here will be resolved to an array of row objects.

    
copy
#Update multiple rows table_service = datastore_service.table("Employee") row_data = [{'name': 'Mathew Jones', 'id': '7211', 'age': '31', 'ROWID': 2136000000034043}, {'name': 'Rhonda Watson', 'id': '7212', 'age': '28', 'ROWID': 2136000000034045}] row_response = table_service.update_rows(row_data)

A sample response is shown below :

    
copy
[ { CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-24 13:22:14:718", CREATEDTIME: "2021-08-24 13:12:55:999", Name: "Mathew Jones", ID : "7211", Age: 31, ROWID: "2136000000034043" }, { CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-24 13:22:14:728", CREATEDTIME: "2021-08-24 13:12:56:001", Name: "Rhonda Watson", ID : "7212", Age: 28, ROWID: "2136000000034045" } ]

Last Updated 2023-12-18 16:20:08 +0530 +0530