pjs.data.delete()



This API is used to delete records from 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. Filter:
    Single condition - created using pjs.data.createCondition API
    --or--
    Array of conditions - created using pjs.data.createCondition API
    --or--
    (String) – SQL syntax, because pjs.data.createCondition does support every possible way of conditioning


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
try { let filter = pjs.data.createCondition("customerNumber", "=", "1"); let results = pjs.data.delete("customers", filter); console.log(results); } catch(error) { console.error(error); }



Example using SQL Syntax
// The SQL Syntax is a fallback option. Know that this syntax may not work against all databases. try { let filter = { whereClause: "substring(customerName,10,1) = 'a' or (customerNumber % 21) = 0"}; let results = pjs.data.delete("customers", filter ); console.log(results); } catch(error) { console.error(error); }