Insert into database

Hey,

I am receiving request from the client side, then I want to insert the data sent into the database using the js (the data sent are json).

Can you give me a sample on how to insert these data into the database?

Hello @Hassan_Serhan

When you say “I am receiving request from the client side” do you mean you receive a request on your own nodejs server or you are talking about Backendless API Services?

Regards, Vlad

In the client side, I set the path of the Backendless API Services.

Alright, you can use all the JS-SDK API inside the Backendless Business Logic. https://backendless.com/docs/bl-js/bl_basic_quick_start_guide_js.html

Here is a doc for saving data https://backendless.com/docs/js/data_single_object_create.html

In this one as example: “Backendless.Data.of( “TABLE-NAME” ).saveSync( { propertyA:” “, propertyB:” "} ); "

After each one of propertyA and propertyB I put the names of variables as in the client side code?

All the Sync methods are deprecated and will be removed soon and also it won’t work in Nodejs ENV, so use:

const result = await Backendless.Data.of( “TABLE-NAME” ).save({ ... })

After each one of propertyA and propertyB I put the names of variables as in the client side code?

It depends on what you need. could you please share minimal code of your API Service

All that I have the variables converted to Json and sent as request to Backendless, I want to insert these data into the database using javascript, so this what I am asking about.

here you go:

class MyService {
  /**
   * @param {Object} object
   */ 
  save(object) {
   return Backendless.Data.of( “TABLE-NAME” ).save(object)
 }
}

Backendless.ServerCode.addService( MyService );
1 Like