Create object


In order to create a record and save the data to our table, we will use the next format and set our attributes with the 

set   command.

var Cars = Simbla.Object.extend("Cars");
var car = new Cars();
car.set("car_year", 2014);
car.set("car_model", "Test car");
car.set("car_code", 12468);
car.set("car_color", "red");
car.set("available", true);
car.set("stock", 5);
car.save(null, {
      success: function(car) {
            alert('New object created with objectId: ' + car.id);
       },
       error: function(car, error) {
             alert('Failed to create new object, with error code: ' + error.message);
       }
});

Here is another example doing the same action. Here we will set our attributes under the  save   command.

var Cars = Simbla.Object.extend("Cars");
var car = new Cars();
car.save({
  car_code: 12468,
  car_model: "Test car",
  car_year: 2014,
  car_color: "red",
  available: true,
  stock: 5,
   }, {
        success: function(car) {
     // Object saved successfully.
       alert('New object created with objectId: ' + car.id);
    },
 
       error: function(car, error) {
        // Object saving failed.
       // error is a Simbla.Error with an error code and message.
          alert('Failed to create new object, with error code: ' + error.message);
      }
 });

After publishing and running the code, you can go to your table in your database and see how a new record has been added with the data you entered. Please make sure you hit the refresh button above your table.

Here is how our table looks after running the code:

As you can see, there are three automatic fields provided by the the system for your convenience and for future use:

1. objectId - a unique string identifying each saved record.

2. createdAt - the exact time and date the record was created.

3. updatedAt - the exact time and date of the last modification made.

About Simbla

Trying to create a website for their own business, Simbla's founders recognized, over the years, a lack of excellent, simple tools available on the market. Therefore, in 2013 Simbla was founded, for the purpose of providing a smart and easy website building solution for all types of businesses. Simbla's founders have more than 15 years of experience with web-based platforms and website building. We are helping SMB's to create a web presence and to evolve easily into a highly competitive market.

In our vision Simbla creates a new environment where websites are meant for everybody!

Social

all rights reserved to simbla inc

2016