Profound.js Intellisense
IntelliSense for the Profound.js APIs is available as of Profound.js 4.2.8 and applies when editing Profound.js modules in Visual Studio Code.
Overview
When developing Profound.js modules in Visual Studio Code, the Profound.js APIs are available through IntelliSense (also known as content assist). IntelliSense is used for understanding references in your code: as you type, it lists the available functions and variables, shows the parameters each function expects, and displays a short description of what the function does.
The profoundjs package includes a TypeScript declaration file (profoundjs.d.ts) that describes the pjs namespace and the objects its APIs return. Visual Studio Code reads this file to provide completion, parameter hints, and descriptions for the Profound.js APIs while you write JavaScript.
Enabling IntelliSense for the Profound.js APIs
To make the Profound.js API definitions available to Visual Studio Code, require the profoundjs module at the top of your script:
require('profoundjs');Visual Studio Code resolves require('profoundjs') using standard Node.js module resolution. Open the module from a folder where the profoundjs package can be found through a node_modules directory, such as your Profound.js instance directory.
Completing Profound.js API Names
Once the module is required, any time you type the pjs namespace followed by a period, Visual Studio Code prompts you with a list of the Profound.js methods available for you to use. Selecting an entry in the list shows the method’s parameters and a short description of the API.
Working with Statement Handles
IntelliSense is especially helpful when working with the Profound.js SQL APIs. The pjs.prepare() API returns a statement handle object that has its own methods. In object-oriented terms, you can compare pjs.prepare() to a constructor, with the returned handle being an instance of a class that exposes methods such as bindParameters(), execute(), fetch(), and close().
When you reference the handle, IntelliSense lists the methods available on that object:
As you start to type a method’s parameters, Visual Studio Code shows the parameter type along with a description of the value that is expected:
Example
Example: Product Search Web Service
This example is the prodlistws.js module shown in the screenshots above. It is a Profound.js web service (API route) module that searches a product table for a description matching a search term and returns the matching rows as JSON. Every Profound.js API call in the module benefits from IntelliSense: pjs.prepare() is completed from the pjs namespace, and bindParameters(), execute(), fetch(), and close() are completed from the statement handle.
Prerequisite: a table PRODUCTSP in the library list with the columns PRID, PRNAME, and PRDESC. Substitute your own table.
prodlistws.js
// Requiring 'profoundjs' lets Visual Studio Code find the Profound.js API definitions,
// so IntelliSense is available for the pjs namespace and for statement handles.
require('profoundjs');
function prodlistws(req, res) {
// Build a LIKE pattern from the "search" query string parameter (for example, ?search=Garmin).
var searchQuery = '%' + (req.query.search || '') + '%';
// pjs.prepare() returns a statement handle. Typing "cursor." lists the handle's methods.
var cursor = pjs.prepare("SELECT prid, prname, prdesc FROM productsp WHERE prdesc LIKE ?");
// Bind the search value to the ? parameter marker. As you type the parameter, IntelliSense
// shows that bindParameters() expects an array of arrays in the form [value, SQL_PARAM_TYPE].
cursor.bindParameters([[searchQuery, SQL_PARAM_INPUT]]);
// Run the prepared statement.
cursor.execute();
// Fetch all remaining rows as plain JavaScript objects, one property per column.
var products = cursor.fetch(SQL_FETCH_ALL);
// Always close the statement handle to release the cursor.
cursor.close();
// Return the matching products to the caller as JSON.
res.json(products);
}
exports.run = prodlistws;Calling the web service with ?search=Garmin returns a JSON array containing one object for each row in PRODUCTSP whose description contains “Garmin”. The property names of each object match the selected column names in lowercase.
Expected output
[
{ "prid": 6, "prname": "Garmin nuvi 1450", "prdesc": "Garmin nuvi 1450 5-inch GPS navigator" },
{ "prid": 7, "prname": "Garmin Forerunner", "prdesc": "Garmin Forerunner 235 GPS running watch" }
]