pjs.getDB()

 

 

This API was added in Profound.js 5.0.0

This API returns a database connection definition object that can be passed to some SQL and Data APIs to specify the desired database connection. 

Parameters

  1. Database connection name (String/optional). A name corresponding to an entry in the databaseConnections configuration option.

    If this parameter is omitted, then the default database connection definition is returned. In Profound.js Spaces, the default database connection is normally the workspace's built-in MariaDB database. However, if the Profound.js Spaces workspace is called from IBM i using the NODERUN command, the default database connection is overridden to work with the calling IBM i database. In this case the workspace's built-in MariaDB database can be accessed by passing connection name "workspace".

Return Value

A database connection definition object that can be passed to the following APIs:

pjs.query()
pjs.parallelQueries()
pjs.allocStmt()
pjs.prepare()
pjs.setConnectAttr()
pjs.getConnection()
pjs.createDataArea()
pjs.retrieveDataArea()
pjs.setDataArea()
pjs.data.add()
pjs.data.get()
pjs.data.getCount()
pjs.data.delete()
pjs.data.update()

The return value is passed to the above APIs as the first parameter, followed by the other parameters as documented for each API.

The database connection definition object also has a property called 'connection' which has a reference to the corresponding entry from the databaseConnections configuration option.

Exception Handling

An exception is is thrown if the database connection name is not valid.

Examples

pjs.query()
pjs.query("select * from mytable where mycol = ? or mycol = ?", [value1, value2]); // Query runs against default database connection. pjs.query(pjs.getDB("crm"), "select * from mytable where mycol = ? or mycol = ?", [value1, value2]); // Query runs against database connection "crm".

 

Data API
const record = { id: 123, firstname: "Joe", lastname: "Customer" }; pjs.data.add("customers", record); // Runs against default database connection. pjs.data.add(pjs.getDB("crm"), "customers", record) // Runs against database connection "crm".

 

Retrieve configuration
const connectionInfo = pjs.getDB().connection; // Default connection. if (connectionInfo.driver === "IBMi") { // IBM i-specific code. } else if (connection.driver === "mysql") { // MySQL/MariaDB-specific code. }