Data API
Â
The pjs.data APIs allows for interaction with database objects without having to write pure SQL syntax. Which make using them simpler and more robust.
These APIs also allow for:
1) More database independent. Since you are not writing the explicit SQL syntax.
2) Can incorporate DbDefn file, which supports things such as data type overrides and shared business logic.
Â
The pjs.query API is very powerful, however it does require that you to write valid SQL syntax that work for the running database.
These Data APIs are created so that you do not need to know much, if any, SQL.
Here are some scenarios where your SQL logic would not be simple:
When your table or column name is also a database reserved name (like from, as, date, etc), you need to escape them in your SQL syntax, and not all databases use the same escape character.
Not all database support all the same data types, such as Oracle does not support Date type parameters, and your SQL syntax and parameters would need to be adjusted.
Not all database support the ? parameter marker, such as Microsoft SQL, and your SQL syntax would differ slightly.
Some database installations support case-sensitive table and column names. If it does, your SQL syntax would need to change.
The SQL syntax may work on one database, but not on another
These Data APIs create the correct SQL statement based on the current database and handle all these scenarios and more...
Â
Compare pjs.query and pjs.data.get
// These 2 lines will return the exact same results
let rcds1 = pjs.query("select * from customers");
let rcds2 = pjs.data.get("customers");
// Here you can see some differences on how to get records with criteria. Both will return the exact same result.
const parm1 = "USA";
const strName = "B"
let rcds3 = pjs.query("select * from customers where country = ? and customerName > ?", [parm1, strName]);
let filter = [
pjs.data.createCondition("country", "=", parm1),
pjs.data.createCondition("customerName", ">", strName)
];
let rcds4 = pjs.data.get("customers", filter);
Â
Â