Create Rows

Create a Single Row

You can create a new row in a Data Store table of the given instance using the newRow() method, as shown below. You must set the values of the rows in the table, by specifying the column name and the corresponding row value as a key-value pair.

The <ROW_INSTANCE> used in the code syntax below is the instance defined in the Row Instance page. The column value is set using the method discussed in the Add a Column Value page.

Parameters:

  • completion: If the operation is successful, the completion block will return the details of the created row, such as its unique ROWID and other meta information. Else, it will return an error.
Note: If a column was created with the is_unique or is_mandatory property enabled, you must ensure that the value is unique or is mandatorily passed, respectively. You must also ensure that the data you pass for a column is of the column's configured data type.

A sample code snippet is shown below:

    
copy
let instance = ZCatalystApp.shared.getDataStoreInstance(tableIdentifier: "1096000000002071").newRow() //Replace this with your Table ID instance.setColumnValue(columnName: "Department_Name", value: "Marketing") instance.setColumnValue(columnName: "Employee_Name", value: "Linda Page") //Replace this with your column name and value instance.create() {(result) in switch result{ case .success ( let row) : print("A new row is successfully created with row id /(row.id)") case .error( let error ) : print( "Error occurred >>> \( error )" ) } }

Create Multiple Rows

iOS SDK enables you to create multiple rows in a table of the given instance at a time. This is done by passing an array containing the rows that need to be inserted in the table. The array is passed as an argument to the create() method, as shown in the code structure below.

You must pass the array of <ROW_INSTANCE>, after creating the instance for each row as explained in the Row Instance page. Their column value must be set as discussed in the Add a Column Value page.

The <DATA_STORE_INSTANCE> used in the code below is the instance created earlier in the Data Store Instance page.

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

Parameters:

  • rows: The array of rows to be created.
  • completion: If the operation is successful, the completion block returns the details of the rows created, such as their ROWIDs and other meta information. Else, it returns an error.

A sample code snippet is shown below:

    
copy
let row_instance1 = ZCatalystApp.shared.getDataStoreInstance(tableIdentifier: "1096000000002071").newRow() //replace your table id here row_instance1.setColumnValue(columnName: "Department_Name", value: "Marketing") row_instance1.setColumnValue(columnName: "Employee_Name", value: "Robert Jones") //Replace this with your column name and value let row_instance2 = ZCatalystApp.shared.getDataStoreInstance(tableIdentifier: "1096000000002071").newRow() //Replace this with your Table ID row_instance2.setColumnValue(columnName: "Department_Name", value: "Finance") row_instance2.setColumnValue(columnName: "Employee_Name", value: "Louis Smith") //Replace this with your column name and value ZCatalystApp.shared.getDataStoreInstance(tableIdentifier: "1096000000002071").create([row_instance1, row_instance2]) {(result) in switch result{ case .success ( let rows) : print("The rows ids which are successfully created are listed below") for row in rows{ print(row.id) } case .error( let error ) : print( "Error occurred >>> \( error )" ) } }

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