Skip to content

Object Level APIs

The Object Level API helps the developer to perform ORM operations at the object (or) entity (or) table level.

\<VMXObj>.startSync

Syntax

<VMXObj>.startSync (syncOptions, successCallback, failureCallback)

Parameters

ParameterTypeDescriptionRequired
syncOptionsJSONThe user can provide options to customize sync behavior.Yes
successCallbackFunctionThe function is invoked on a successful sync.Yes
failureCallbackFunctionThe function is invoked on an error in sync with the cause of failure as an argument.Yes

Sync Options

OptionsTypeDescriptionsRequired
downloadBatchSizeNumber (or) StringThe downloadBatchSize option defines record based batching in downloads. Make sure to provide appropriate batch size (number of records) based on backend’s ability (to support the same). downloadBatchSize is 500(records) by default. Default BatchSize is assumed if the supplied value is less than or equal to 0.No
uploadBatchSizeNumber (or) StringuploadBatchSize option defines record based batching in uploads. uploadBatchSize is 50 (records) by default. Default BatchSize is assumed if the supplied value is less than or equal to 0.No

Example

function successCallback(object){
   //Handle sync success response.
  } 
function failureCallback (error){
   //Handle sync failure response.
  } 
try{
    var syncObject = new voltmx.sdk.VMXObj("Employee");
    var syncOptions = {};

    //Set upload and download BatchSize.
    syncOptions.downloadBatchSize = 100;
    syncOptions.uploadBatchSize = 200; 
    syncObject.startSync(syncOptions, successCallback,failureCallback);
  } catch (err) {
      //Handles Exception.
  }

\<VMXObj>.get

Syntax

<VMXObj>.get(options, successCallback, failureCallback)

Parameters

ParameterTypeDescriptionRequired
options  JSONIf the options parameter is omitted, all the records are returned.Yes
successCallbackFunctionThe function is invoked when get operation is successful.Yes
failureCallbackFunctionThe function is invoked on an error in get operation with the cause of failure as an argument.Yes

Options Keys

KeysTypeDescriptionRequired
primaryKeysJSON (or) TableSpecify the primary keys to use, for the select query. Use record's primary key column names as key and respective values to populate primaryKeys JSON.No
whereConditionAsAStringStringSpecify where condition for the select query if primary keys are not provided. Key Name: whereConditionAsAString and the value is string.No
orderByMapJSON elementsSpecify the way the data must be arranged in ascending (or) descending order of the column name. Key Name: orderByMap and value is an array of the dictionary.No
whereConditionJSONSpecify the where condition for the select query if primary keys are not provided. Key Name: whereCondition and values are column names and their respective values.No
likeConditionJSON (or) TableList of column names and their respective values according to which the records are to be fetched.No

Example

//----- Example : Get all  --------
function successCallback(records){
     //records is an array of records. each record is a dictionary.
} 
function failureCallback(error){
     voltmx.print(“unable to retrieve records from db”+ error.code);
} 
var categories = new VMXObj("CATEGORY");
//all records of object CATEGORY are returned as an argument to success callback.
categories.get( null, successCallback, failureCallback);  

//------- Example : get with orderBy clause --------
function successCallback(records){
    //records is an array of records. each record is a dictionary.
} 
function failureCallback(error){
    voltmx.print(“unable to retrieve records from db”+ error.code);
} 
var categories = new VMXObj("CATEGORY");
var orderByMap = [];
orderByMap.push({"CategoryID":"DESC"});
orderByMap.push({"CategoryName":"ASC"}); 
var options = {};
options["orderByMap"] = orderByMap; 
//all records of object CATEGORY are returned as an argument to success callback ordered by CategoryID and CategoryName.
categories.get(options, successCallback, failureCallback); 
//------ Example : get by PK  --------
function successCallback(records){
      //records is an array of records. each record is a dictionary.
} 
function failureCallback(error){
     voltmx.print(“unable to retrieve records from db”+ error.code);
} 
var categories = new VMXObj("CATEGORY");
var options = {};

//Primary keys or a where clause can be used
var primaryKeys = {};
primaryKeys["CategoryID"] = "2233";
options["primaryKeys"]= primaryKeys; 
// record with PK CategoryID with value "2233"  of object CATEGORY are returned as an argument to success callback.
categories.get( options, successCallback, failureCallback);

//---- Example : get by where clause --------
function successCallback(records){
       //records is an array of records. each record is a dictionary.
} 
function failureCallback(error){
      voltmx.print(“unable to retrieve records from db”+ error.code);
}  
var categories = new VMXObj("CATEGORY");
var whereClause = "Category_PN = '7'";
var options = {};
options["whereConditionAsAString"] = whereClause; 
//Invoking get returns  record with Category_PN = 7 .
categories.get(options, successCallback, failureCallback);

\<VMXObj>.create

Syntax

<VMXObj>.create(record, options, successCallback, failureCallback)

Parameters

ParameterTypeDescriptionRequired
recordJSONSpecify the record to be created in the database under a given object.Yes
optionsJSONReserved for future use. Supply null or empty JSON as options.Yes
successCallbackFunctionThe function is invoked when records are created successfully. Newly created record is returned through successCallback.Yes
failureCallbackFunctionThe function is invoked on an error with the cause of failure as an argument.Yes

Example

function successCallback(response){
    voltmx.print("Record created successfully with primary keys: " + response["CATEGORY_ID"]);
} 
function failureCallback(error)
    voltmx.print("Create is failed" + JSON.stringify(error));
} 
var category = new voltmx.sdk.VMXObj("CATEGORY");
var record = {}; 
// CATEGORY_ID is the autogenerated primary key
record["CATEGORY_PN"] = Number("7");
record["CATEGORY_DES"] = "Creating a new record"; 
category.create(record, {}, successCallback, failureCallback);

\<VMXObj>.updateByPK

Syntax

<VMXObj>.updateByPK(record, options, successCallback, failureCallback)

Parameters

ParameterTypeDescriptionRequired
recordJSONA dictionary containing column name and value pairs that are to be updated.Yes
optionsJSONA dictionary containing primaryKeys.Yes
sucessCallbackFunctionThe function is invoked when records are updated successfully.Yes
failureCallbackFunctionThe function is invoked on an error with the cause of failure as an argument.Yes

Example

function successCallback(response){
   voltmx.print("Record Updated successfully");
}

function failureCallback(error)
    voltmx.print("Update failed with error: " + JSON.stringify(error));
}

var category = new voltmx.sdk.VMXObj("CATEGORY");
var options = {};
var record = {};
var primaryKeys = {};

record["CATEGORY_DES"] = "Update existing record";
primaryKeys["CATEGORY_ID"] = "1234"
options["primaryKeys"] = primaryKeys;

category.updateByPK(record, options, successCallback, failureCallback);

\<VMXObj>.deleteByPK

Syntax

<VMXObj>.deleteByPK(options, successCallback, failureCallback)

Parameters

ParameterTypeDescriptionRequired
optionsJSONA dictionary containing mandatory key primaryKey which contains the PK (column name and value). In case of a composite PK, the dictionary will contain multiple key-value pairs.Yes
successCallbackFunctionThe function is invoked when records are deleted successfully.Yes
failureCallbackFunctionThe function is invoked on an error with the cause of failure as an argument.Yes

Example

//Success callback
function successCallback(){
     voltmx.print("record updated successfully");
}  
//Failure callback
function failureCallback(error){
     voltmx.print(error.code);
}  
//Sample to delete a record using PK
var categories = new voltmx.sdk.VMXObj(“CATEGORY”);
var primaryKeys = {};
primaryKeys[“CATEGORY_ID”] = ”1234”;
var options = {};
options["primaryKeys"]= primaryKeys; 
//Invoke the delete API
categories.deleteByPK(options, successCallback, failureCallback);  
//Sample to delete a record using composite primary key
var categories2 = new voltmx.sdk.VMXObj(“CATEGORY2”);
var primaryKeys = {};
primaryKeys[“CATEGORY_KEY1”] = ”1234”;
primaryKeys[“CATEGORY_KEY2”] = ”23”;
var options = {};
options["primaryKeys"]= primaryKeys; 
//Invoke the delete API to delete record having composite primary key(CATEGORY_KEY1 and CATEGORY_KEY2)
categories2.deleteByPK(options, successCallback, failureCallback);