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. 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.

    
copy
<ROW_INSTANCE>.create( success: (ZCatalystRow) → Unit, failure: ((ZCatalystException) → Unit)? ): ZCatalystRequest<ZCatalystResponse<ArrayList<ZCatalystRow>>>?
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
val row = ZCatalystApp.getInstance().getDataStoreInstance().getTableInstance("EmployeeDetails").newRow() //Replace this with your table name row.setColumnValue("Department_Name", "Marketing") //Replace this with your column name and its value row.setColumnValue("Employee_ID", "109223") //Replace this with your column name and its value row.setColumnValue("Employee_Name", "Robert Smith") //Replace this with your column name and its value row.create( { success -> println("New row created successfully $success") }, { exception -> println("Failed to create a new row! $exception") } )

Create Multiple Rows

Catalyst Android SDK enables you to create multiple rows at a time in a table of the given instance. 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 createRows() 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>.createRows( rows: ArrayList<ZCatalystRow>, success: (List<ZCatalystRow>) → Unit, failure: ((ZCatalystException) → Unit)? ): ZCatalystRequest<ZCatalystResponse<ArrayList<ZCatalystRow>>>?

Parameters:

  • rows: The array of rows to be created

A sample code snippet is shown below:

    
copy
ZCatalystApp.getInstance().getDataStoreInstance().getTableInstance("EmployeeDetails").createRows( //Replace this with your table name rowsList, //Set the names and values of the columns and add them to an arrayList { rows -> println("The IDs of the rows that were successfully created are listed below:") for (row in rows){ println("${row.id}") } }, { exception -> println("Add Rows Failed! $exception") })

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