Inserting a Row in the Database
We can create a new row in just one simple SQL transaction called from a Node.js function
In your Cloud Backend interface :
- Click on API tab
- New function button
![IFrame](https://1e64.net/support-documentatio-cb1e1b/uploads/1595335462401-Screenshot-2020-07-21-at-15.42.15.png)
Then you can write your function like this. Note that we receive the parameters: firstName, lastName, and email that we will insert in the 'users' table
![](https://1e64.net/support-documentatio-cb1e1b/uploads/1595335462206-Screenshot-2020-07-21-at-15.40.58.png)
Click on 'Try' button and check on your table :
![](https://1e64.net/support-documentatio-cb1e1b/uploads/1595335462477-Screenshot-2020-07-21-at-15.41.12.png)
A common use case is creating a new row in your database then obtaining the latest id inserted. Here is how you can accomplish that in just one simple SQL transaction called from a Node.js function:
var cloudbackend = require('appdrag-cloudbackend');
cloudbackend.init(APIKey, appID);
cloudbackend.sqlSelect("INSERT INTO Users (name, email, password) "
+"values('john doe', 'john@doe.com', 'Test97_626p'); SELECT LAST_INSERT_ID() as newUserID;")
.then( function(response) {
var result = JSON.parse(response);
var newUserID = result.Table[0].newUserID;
callback(null, newUserID); //return the newUserID
});
This function uses our NPM package: appdrag-cloudbackend on NPM
In your Cloud Backend interface :
- Click on API tab
- New function button
![IFrame](https://1e64.net/support-documentatio-cb1e1b/uploads/1595335462401-Screenshot-2020-07-21-at-15.42.15.png)
Then you can write your function like this. Note that we receive the parameters: firstName, lastName, and email that we will insert in the 'users' table
![](https://1e64.net/support-documentatio-cb1e1b/uploads/1595335462206-Screenshot-2020-07-21-at-15.40.58.png)
Click on 'Try' button and check on your table :
![](https://1e64.net/support-documentatio-cb1e1b/uploads/1595335462477-Screenshot-2020-07-21-at-15.41.12.png)
A common use case is creating a new row in your database then obtaining the latest id inserted. Here is how you can accomplish that in just one simple SQL transaction called from a Node.js function:
var cloudbackend = require('appdrag-cloudbackend');
cloudbackend.init(APIKey, appID);
cloudbackend.sqlSelect("INSERT INTO Users (name, email, password) "
+"values('john doe', 'john@doe.com', 'Test97_626p'); SELECT LAST_INSERT_ID() as newUserID;")
.then( function(response) {
var result = JSON.parse(response);
var newUserID = result.Table[0].newUserID;
callback(null, newUserID); //return the newUserID
});
This function uses our NPM package: appdrag-cloudbackend on NPM