Get Rows

Get a Specific Row

You can retrieve a single specific row from a Data Store table of the given instance using the getRow() method. This is done by passing the unique ROWID of the row as the argument to this 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>.getRow( id: Long, success: (ZCatalystRow) → Unit, failure: ((ZCatalystException) → Unit)? ): ZCatalystRequest<ZCatalystResponse<ZCatalystRow>>?

Parameters:

  • id: The unique ROWID of the particular row that needs to be retrieved

A sample code snippet is shown below:

    
copy
val table = ZCatalystApp.getInstance().getDataStoreInstance().getTableInstance("EmployeeDetails") //Replace this with your table name table.getRow(2823000000014176, //Replace this with your Row ID { row -> println("Get Row Success") println(" The row details are: ${row.getData()}") }, { exception -> println("Get row failed! $exception") })

Get Rows Through Pagination

You can retrieve all the rows from a table in the Data Store by incorporating pagination in your code. Pagination allows you to fetch the rows of a table in batches or pages through iterations.

For example, if you require the rows to be fetched in batches of 100 as individual pages, you can define the maximum rows to be fetched in each page and specify the count using maxRows as shown below.

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

    
copy
<TABLE_INSTANCE>.getRows(maxRows: Int, success: (List<ZCatalystRow>, ResponseInfo) -> Unit, failure: ((ZCatalystException) -> Unit)? = null): ZCatalystRequest<ZCatalystResponse<ArrayList<ZCatalystRow>>>?

Parameters:

  • maxRows: The maximum number of rows to be fetched in this iteration

A sample code snippet is given below:

    
copy
ZCatalystApp.getInstance().getDataStoreInstance().getTableInstance("EmployeeDetails").getRows( 10, { rows, info ->{ println("The token for next set of rows - ${info.nextToken}") println("Boolean to know if there are records in next page - ${info.moreRecords}") } }, { exception -> println("Failed to get the rows! $exception") })

Additionally, after each execution of the loop, you will receive a token string in the response that authorizes the subsequent fetching of data. You can fetch this token through info.nextToken, and pass it as the value for nextToken during the subsequent iteration. During the first execution of the loop, the nextToken string is not passed.

You can also verify the number of pending rows to be fetched through info.moreRecords as shown in the code snippet.

You can fetch the next set of rows by passing the nextToken as well as maxRows if you require pagination to continue. This can be done as shown below.

    
copy
<TABLE_INSTANCE>.getRows(nextToken: String, maxRows: Int, success: (List<ZCatalystRow>, ResponseInfo) -> Unit, failure: ((ZCatalystException) -> Unit)? = null): ZCatalystRequest<ZCatalystResponse<ArrayList<ZCatalystRow>>>?

Parameters:

  • maxRows: The maximum number of rows to be fetched in this iteration
  • nextToken: The authorization token to fetch the next set of rows

A sample code snippet is given below:

    
copy
ZCatalystApp.getInstance().getDataStoreInstance().getTableInstance("EmployeeDetails").getRows( "1000.6f********" , 20 , { rows, info ->{ println("The token for next set of rows - ${info.nextToken}") println("Boolean to know if there are records in next page - ${info.moreRecords}") } }, { exception -> println("Failed to get the rows! $exception") })

You can fetch the nextToken and moreRecords information until info.moreRecords returns FALSE.

If you prefer to fetch all pending rows after the first iteration and don’t want to set a maxRows limit, you can do so in the following manner:

    
copy
<TABLE_INSTANCE>.getRows(nextToken: String, success: (List<ZCatalystRow>, ResponseInfo) -> Unit, failure: ((ZCatalystException) -> Unit)? = null): ZCatalystRequest<ZCatalystResponse<ArrayList<ZCatalystRow>>>?

Parameters:

  • nextToken: The authorization token to fetch the next set of rows

A sample code snippet is given below:

    
copy
ZCatalystApp.getInstance().getDataStoreInstance().getTableInstance("EmployeeDetails").getRows( "1000.6f********", { rows, info ->{ println("The token for next set of rows - ${info.nextToken}") println("Boolean to know if there are records in next page - ${info.moreRecords}") } }, { exception -> println("Failed to get the rows! $exception") })

This will make info.moreRecords return FALSE.


Get All Rows

You can retrieve all the rows of a table of the given instance using the getRows() method, as shown in the code syntax below. If the operation is successful, this method will return all the rows of the table without any filters or conditions.

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

    
copy
<TABLE_INSTANCE>.getRows( success: (List<ZCatalystRow>,ResponseInfo) → Unit, failure: ((ZCatalystException) → Unit)?= null): ): ZCatalystRequest<ZCatalystResponse<ArrayList<ZCatalystRow>>>?

A sample code snippet is shown below:

    
copy
val table = ZCatalystApp.getInstance().getDataStoreInstance().getTableInstance("EmployeeDetails") //Replace this with your table name table.getRows( { rows, info ->{ println("The token for next set of rows - ${info.nextToken}") println("Boolean to know if there are records in next page - ${info.moreRecords}") } }, { exception -> println("Failed to get the rows! $exception") })
Note: Because this is an operation to fetch all the rows, you can ignore the info.nextToken. This will return all the rows available without pagination. The info.moreRecords will also return FALSE if all the rows are fetched.

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