Documentation
Utilities
General utilities exposed to CYBERQUEST scripts through CQ.Utils.
Overview
The CQ.Utils namespace provides general utilities for use in customizable CYBERQUEST scripts, including Data Transformation Service (DTS) and alert scripts.
Available members
| Access path | Exported utility |
|---|---|
CQ.Utils.moment | moment |
CQ.Utils.recursiveCleanupObjectProperties | recursiveCleanupObjectProperties |
CQ.Utils.LocalStorage | LocalStorage |
CQ.Utils.CQDataBase | CQDataBase |
moment
This object manipulates date and time related information. Click this link for more information.
Call CQ.Utils.moment() with no arguments for the current time, or pass a supported date value and optional format. It returns a Moment object.
recursiveCleanupObjectProperties
This method takes an object and recursively goes through all the objects or arrays that it contains, renaming all the keys such that the @ and : symbols are replaced with _. This way, the keys will present a cleaner format.
Parameters: inputObject
Usage:
CQ.Utils.recursiveCleanupObjectProperties(inputText);
Returns the cleaned object. Nested objects and arrays are processed recursively.
LocalStorage
The class is designed to make temporary data persist. It also acts as a caching module. (key->value)
set
Keeps a value in the local storage under a certain key. Optionally, expiring time can be specified in seconds.
Parameters:
- listName
- name
- value
- ttl (900 by default, -1 is indefinitely)
Usage:
CQ.Utils.LocalStorage.set(listName, keyName, value);
Returns the runtime storage target’s result. Returns false when either name is missing or shorter than two characters, when value is null, or when ttl is not a finite number.
get
Returns a stored value. If the value does not exist, it will return an empty object in order to simplify the validation checks.
Parameters:
- listName
- name
Usage:
CQ.Utils.LocalStorage.get(listName, keyName);
Returns the stored value. Returns {} for invalid names, missing data, or storage errors.
erase
Deletes a single value from the local storage.
Parameters:
- listName
- name
Usage:
CQ.Utils.LocalStorage.erase(listName, keyName);
Returns undefined.
clear
Deletes all values from the local storage.
Parameters:
- listName
Usage:
CQ.Utils.LocalStorage.clear(listName);
Returns undefined after a successful clear, or false when the storage target throws an error.
removeKeysStartingWith
Deletes from local storage all values with keys that start with a certain string.
Parameters:
- listName
- name
Usage:
CQ.Utils.LocalStorage.removeKeysStartingWith(listName, name);
Returns undefined on success, or false when the storage target throws an error.
listKeys
CQ.Utils.LocalStorage.listKeys(listName);
listName defaults to null. Invalid names return []. The current wrapper does not return the storage target’s value for a valid name and therefore returns undefined.
listKeysByPattern
CQ.Utils.LocalStorage.listKeysByPattern(pattern);
Returns the matching keys from the storage target. A missing pattern or a pattern shorter than two characters returns [].
CQDataBase
CQ.Utils.CQDataBase provides database helpers for scripts that receive a MySQL connection ID. Its basic data operations are:
CQ.Utils.CQDataBase.getData(MySQLConnectionID, tableName, limit, whereClause);
CQ.Utils.CQDataBase.getReportParentID(MySQLConnectionID, parentGUID);
CQ.Utils.CQDataBase.insertData(MySQLConnectionID, tableName, values);
CQ.Utils.CQDataBase.updateData(MySQLConnectionID, tableName, values, whereClause, limit);
CQ.Utils.CQDataBase.deleteData(MySQLConnectionID, tableName, whereClause, limit);
CQ.Utils.CQDataBase.truncateData(MySQLConnectionID, tableName);
Database method parameters and returns
| Method | Parameters | Defaults | Returns |
|---|---|---|---|
getData | Connection ID, table name, limit, where clause. | limit = 10000, whereClause = "" | Runtime database target result. |
getReportParentID | Connection ID and parent GUID. | None. | Matching report ID, or null. |
insertData | Connection ID, table name, values object. | values = {} | Runtime database target result. |
updateData | Connection ID, table name, values, where clause, limit. | values = {}, whereClause = "", limit = 1 | undefined |
deleteData | Connection ID, table name, where clause, limit. | whereClause = "", limit = 1 | undefined |
truncateData | Connection ID and table name. | None. | Runtime database target result. |
Treat table names, where clauses, and values as trusted administrative input. Build where clauses carefully and do not include untrusted text.