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. The datastore_service reference used below is already defined in the component instance page.

# Get A Single Row table_service = datastore_service.table("CITY") row_data = table_service.get_row(5249000000032385)

A sample response is shown below :

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

Note: The maxRows parameter is optional. The SDK call will return 200 rows in a single page by default if this value is not specified.

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.

Note: Pagination has been made available from the Node.js SDK v2.1.0 update. This will not be available in the older versions of the Node.js SDK.
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:

{ "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:

{ "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 2023-12-18 16:20:08 +0530 +0530