JavaScript User Functions
In addition to SQLite engine built in SQL functions and App Builtin SQL Functions it is possible to define user SQL functions with the JavaScript language.
The JS User Function editor is available from the side menu or:
Storage
Functions defined in this editor are stored inside the SQLite database in a table named__js_functions
. This provide more consistency in case you move the database to another device with the same DBCompass for SQLite application.
Examples
Single value function
Javascript Editor
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
};
SQL Script
SELECT fahrenheit, toCelsius(fahrenheit) AS celsius
FROM temperature
Function with database access
JS Database Object reference
Javascript Editor
async function mySubQuery(value) {
const sql = 'SELECT * FROM table1 WHERE id = ?';
const result = await db.query(sql, value);
return result.at(0)?.name;
};
SQL Script
SELECT mySubQuery(fkTable2)
FROM table1