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 <DATA_STORE_INSTANCE> used in the code below is the instance defined in the Data Store Instance page.

    
copy
<DATA_STORE_INSTANCE>.getRow(id : Int64, completion: @escaping (Result<ZCatalystRow, ZCatalystError>) -> Void)

Parameters:

  • id: The unique ROWID of the particular row that needs to be retrieved
  • completion: If the operation is successful, the completion block will return the details of the row. Else, it will return an error.

A sample code snippet is shown below:

    
copy
ZCatalystApp.shared.getDataStoreInstance(tableIdentifier : "EmployeeDetails").getRow(id: 1096000000002845){( result ) in // Replace this with your Table identifier and ROW ID here switch result{ case .success ( let row) : print(row.id) case .error( let error ) : print( "Error occurred >>> \( error )" ) } }

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.

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 pass this as the value for nextToken during the subsequent iteration. During the first execution of the loop, the nextToken string is not passed.

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

    
copy
<DATA_STORE_INSTANCE>.getRows(nextToken : String?, maxRecord : String?, completion: @escaping (Result<[ZCatalystRow], ZCatalystError>) -> Void)

Parameters:

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

If you prefer to fetch all pending rows after the first iteration, you can avoid passing the maxRows limit. After all the rows are fetched, the pagination will be complete.


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 <DATA_STORE_INSTANCE> used in the code below is the instance defined in the Data Store Instance page.

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

Parameters:

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

A sample code snippet is shown below:

    
copy
ZCatalystApp.shared.getDataStoreInstance(tableIdentifier : "EmployeeDetails").getRows{ ( result ) in //Replace this with your table name switch result{ case .success ( let rows) : for row in rows{ print(row.id) } case .error( let error ) : print( "Error occurred >>> \( error )" ) } }

Last Updated 2023-09-25 19:48:26 +0530 +0530