Insert Rows

You can insert a new row in a table in the Catalyst Data Store by referring to the table’s unique ID or name. You can also insert multiple rows in a table as explained in the next section.

The table_service reference used in the code below can either be a table instance or table meta created earlier.

Note:
  • The table and the columns in it must already be created. You can create a table and the columns for it from the console.

  • You will be able to insert upto 5000 records in each table per project in the development environment. You can create upto 25,000 records overall in each project in the development environment. There are no upper limits for record creation in the production environment.

Insert a Single Row

You must create a dictionary containing the row details in a {column name : column value} format, and pass it as an argument to the insert_row() method, as shown below. This inserts the rows in the table that you refer by its unique tablename or tableID.

A unique ID value for the row is automatically generated once the row is inserted. The datastore_service reference used below is already defined in the component instance page.

    
copy
#Insert a single row in the table table_service = datastore_service.table("Employee") row_data = {'name': 'George Hamilton', 'id': '6868', 'age': '22'} row_response = table_service.insert_row(row_data)

A sample response is shown below :

    
copy
{ CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-16 16:30:12:799", Name: "George Hamilton", Age: 22, ID: 6868, CREATEDTIME: "2021-08-16 16:30:12:799", ROWID: "2136000000011015" }

Insert Multiple Rows

You can insert multiple rows in a table by constructing an array that contains the rows, and passing it as an argument to the insert_rows() method as shown below. The datastore_service reference used below is already defined in the component instance page.

This returns a response containing an array of row objects.

    
copy
table_service = datastore_service.table("Employee") row_data = [{'name': 'Mark Wellington', 'id': '7218', 'age': '29'}, {'name': 'Zendaya Jones', 'id': '3211', 'age': '32'}] row_response = table_service.insert_rows(row_data)

A sample response is shown below :

    
copy
[ { CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-25 13:55:04:904", Name: "Mark Wellington", Age: 29, ID: 7218, CREATEDTIME: "2021-08-25 13:55:04:904", ROWID: 2136000000011015 }, { CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-25 13:55:04:906", Name: "Zendaya Jones", Age: 32, ID: 3211, CREATEDTIME: "2021-08-25 13:55:04:906", ROWID: 2136000000011016 } ]

Last Updated 2023-12-18 16:20:08 +0530 +0530