Get Rows
You can retrieve a single row or multiple rows of data from a table in the Catalyst Data Store. The table_service reference used in these code snippets can either be a table instance or table meta.
Get A Single Row
You can fetch a single row from the table using the get_row() method. You must pass the unique RowID of the row to this method as shown in the code snippet below. To know more about the component instancedatastore_service and the table instancetable_service used below, please refer to their respective help sections.
Parameters Used
Parameter Name | Data Type | Definition |
---|---|---|
rowID | String | A Mandatory parameter. Will store the ID of the row whose details has to be retrieved. |
copy# Get A Single Row datastore_service = app.datastore() table_service = datastore_service.table("CITY") row_data = table_service.get_row(5249000000032385)
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", CITYNAME: "Pune", ROWID: "5249000000032385" }
Get All Rows Through Pagination
You can retrieve all the rows of data from a table in the Data Store by incorporating pagination in your code using the get_paged_rows() function. Pagination allows you to fetch the rows of a table in batches or pages through iterations.
This iteration is executed until all the rows are fetched, which is validated by a simple if condition, as shown in the code below. You can refer to the table by its unique tablename.
For example, if you require the rows to be fetched in batches of 100 as individual pages, you can define a variable for the maximum rows to be fetched in each page and specify the count. The sample code below assigns max_rows as 100.
Additionally, you will receive a token string in the response data that authorizes the subsequent fetching of data. You can fetch this token through next_token, and pass it as the value for next_token during the subsequent iteration, as shown in the code below. During the first execution of the loop, the value for the next_token string is assigned as None. The next set of records are fetched through more_records in the response data.
Parameters Used
Parameter Name | Data Type | Definition |
---|---|---|
next_token | String | A Mandatory parameter. Will store the token from the response data, authorizing subsequent data retrieval. |
max_rows | Numeric | A Optional parameter. Will hold the the number of batches in which the rows has to be fetched. |
copydatastore_service = app.datastore() table_service = datastore_service.table("Aliens") def getMyPagedRows(next_token=None, more_records=True): rows = table_service.get_paged_rows(next_token, max_rows=100) more_records = rows['more_records'] if not more_records: return None next_token = rows['next_token'] return getMyPagedRows(next_token, more_records) getMyPagedRows()
When the more_records parameter is set to true, the sample response is shown below:
copy{ "status": 200, "content": [ { "CREATORID": "3359000000006003", "MODIFIEDTIME": "2022-01-11 18:18:24:855", "CITYNAME": "New York", "CREATEDTIME": "2022-01-11 18:18:24:855", "ROWID": "5249000000032385" }, { "CREATORID": "3359000000006003", "MODIFIEDTIME": "2022-01-11 18:18:25:117", "CITYNAME": "Houston", "CREATEDTIME": "2022-01-11 18:18:25:117", "ROWID": "5249000000032386" }, { "CREATORID": "3359000000006003", "MODIFIEDTIME": "2022-01-11 18:18:25:120", "CITYNAME": "Chicago", "CREATEDTIME": "2022-01-11 18:18:25:120", "ROWID": "5249000000032387" } ], "message": "OK", "more_records": true, "next_token": "{{token}}" }
When the more_records parameter is set to false, the sample response is shown below:
copy{ "status": 200, "content": [ { "CREATORID": "3359000000006003", "MODIFIEDTIME": "2022-01-11 18:18:43:556", "name": "San Diego", "CREATEDTIME": "2022-01-11 18:18:43:556", "ROWID": "5249000000032385" }, { "CREATORID": "3359000000006003", "MODIFIEDTIME": "2022-01-11 18:18:43:557", "name": "Phoenix", "CREATEDTIME": "2022-01-11 18:18:43:557", "ROWID": "5249000000032386" }, { "CREATORID": "3359000000006003", "MODIFIEDTIME": "2022-01-11 18:18:43:568", "name": "Seattle", "CREATEDTIME": "2022-01-11 18:18:43:568", "ROWID": "5249000000032387" } ], "message": "OK", "more_records": false }
Last Updated 2025-03-28 18:24:49 +0530 +0530
Yes
No
Send your feedback to us