Insert Rows

You can insert a new row of data or a record in a table in the 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 reference used in the code below can either be a table instance or a 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 JSON object containing the row details in a {column name : column value} format, and pass it as an argument to the insertRow() method as shown below. This inserts the row in the table that you refer by its name or unique Table ID. A unique RowID value for the row is automatically generated once a row is inserted.

The promise returned here will be resolved to a JSON row object.

    
copy
//Create a JSON object with the rows to be inserted let rowData = { Name: `George Hamilton`, Age: 22, ID: 6868 }; //Use the table meta object to insert the row which returns a promise let datastore = app.datastore(); let table = datastore.table('EmpDetails'); let insertPromise = table.insertRow(rowData); insertPromise.then((row) => { console.log(row); });

A sample response that you will receive for each version is shown below:

    
copy
{ CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-16 16:29:10:499", Name: "George Hamilton", Age: "22", ID: "6868", CREATEDTIME: "2021-08-16 16:29:10:499", ROWID: 2136000000011011 }

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 insertRows() method as shown below. The promise returned here is resolved to an array containing the row objects.

    
copy
//Create a JSON array with the rows to be inserted let rowData = [{ Name: `Mark Wellington`, Age: 29, ID: 7218 }, { Name: `Zendaya Jones`, Age: 32, ID: 3211 } ]; //Use the table meta object to insert multiple rows which returns a promise let datastore = app.datastore(); let table = datastore.table('EmpDetails'); let insertPromise = table.insertRows(rowData); insertPromise.then((rows) => { console.log(rows); });

A sample response that you will receive is shown below. The response is the same for both versions.

    
copy
[ { CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-25 13:55:04:904", Name: "Mark Wellington", Age: "92", ID: "7218", CREATEDTIME: "2021-08-25 13:55:04:904", ROWID: 2136000000038008 }, { 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: 2136000000038010 } ]

Last Updated 2024-04-03 14:37:15 +0530 +0530