Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Content Freeze

As of July 25th, 2023, there is a content freeze on this page.

This API is used to add records to a database object.

Parameters

  1. Database Connection Definition:
    (Object / Optional) - A database connection definition object returned from pjs.getDB(). If not passed, the default database connection will be used.

  2. Database Object:
    (String) Database object name. The name can be qualified with a library/schema. If not qualified the pathlist will be used to resolve the object.
    --or--
    (String) DbDefn file name (with the extension). The file can be qualified with a directory. If not qualified the pathlist will be used to resolve the object.
    --or--
    (Object) DbDefn instance.

  3. Data: (object) - the object that contains the column names and values.
    (Note, this object can contain more, or less, properties then the actual table.  It only uses the matched names.


Returned Object

The returned object will contain several properties based on the type of database being used.

  • mssql and mysql database will contain a property named identityId for the record that was just added if the table has an auto increment primary key.


Exception Handling

An Error instance will be thrown along with these additional properties:

  • sqlstate - The error state.
  • sqlcode - The error code.
  • sqlMessage - The message text.


Example
var record = {
  id: counter,
  firstname: fname,
  lastname: lname,
  dob: null
}

try {

  let result = pjs.data.add("customers", record);
  console.log(result);

} catch(error) {
 console.error(error);
}
  • No labels