Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Name the Module File name --> product.DbDefn.js
    1. The module file name must end with .DbDefn.js
    2. The first part of the name "product" is how your pjs program(s) will reference it.
  2. Describing the table:
    1. useSQL - required - Set this to true so that all PJS programs will access this file using an SQL interface.  If you are not using an IBM i database, it will run as if it was set to true.
    2. dbObject - required - Set this to the actual database object name, can be the name of a table or a view..  (this does not need to make the file name).uniqueKey - required - This is needed to be able to
    3. useSQL - optional- Set this to true so that all PJS programs will access this file using an SQL interface.  This is required is you are using an IBM i database.  All other databases only support sql.
    4. uniqueKey - optional - If the table/view does not have a primary (unique) keys defined then this is required.  If this is a SQL view then this is required. If set, this will be used to correctly read 1 record at a time in a uniquely unique order.
      1. field - the database column name – should be considered case sensitivename
      2. ascending: true or false if the column should be sorted in ascending order, default is true
    5. dbSchema - optional - Set this to the actual database library/schema.  You would normally not need to use this.
    6. format - optional - When converting RPG programs to Profoundjs programs this is required.  This is the record format name of the IBM i table.
    7. overrides - optional - this is where you can override specific fields types and values
      1. There are several reasons where you may need this.  Just to name a few:
        1. The database does not support storage of that type of field (such as with Oracle and a Time type field)
        2. The database you choose to stores dates as number or string, but you want the UI to show them as true dates
        3. The database you choose to stores 2 separate fields for Date and Time, but you want to put them together as a single Date and Time field
        4. The database does not allow storage with that same definition (such as char 1024, some database may require you to make that varying)
        5. The database does not support storing of packed value, but the converted module is coded with packed modules

 

Below is showing an example of this module file.  If you have a lot of tables, you may want to better organize them.This example also shows a couple different examples ways on how you can use that these overrides property.

  • Field named "prcatid" that is stored in the database as character, but will be referenced within the pjs programs as decimal.
  • Field name "prtime" that is stored in the database as character, but will be referenced with the pjs programs as time.

Code Block
module.exports = {
  useSQL: true,
  dbObject: "product",


format: "product",   uniqueKey: [
    { field: "prid", ascending: true }
  ],
  overrides: {
    prcatid: {
      type: "decimal",
      length:5,
      decimals:0,
      transformToDb: function(value) { return thisvalue.toString().padStart(5,"0") },
      transformFromDb: function(value) { return Number(thisvalue) },
    },
    prtime: {
      type: "time",
      transformToDb: profound.utils.timeToCharTransform,
      transformFromDb: profound.utils.charToTimeTransform
    }
  }
}

...

  • If you are using an IBM i database, you can set the this useSQL to false which will revert .  This will cause your pjs modules to go back to using the standard IBMi record level file operation commandsoperations
  • If you delete that this DbDefn module file, which will revert back to using the standard IBMi record level file operation commands
  • If you are not using an IBM i database, this This DbDefn module file is required to exist in order to use our Record Level API'sany of the RLA APIs for any non IBMi database.

 

Here is a simple pjs program that reads all the records of a table.  It is just like any other pjs program module using RLA.  You do not need to change any of your logic to switch from standard RLA function to the new RLA via SQL functions.

Code Block
function products() {
    pjs.defineTable("product", { read: true, keyed: true });
    product.positionTo(0);

    var data = [];
    var record = product.fetch();
    while (!pjs.endOfData()) {
        data.push(record);
        record = product.fetch();
    }
   
    console.log(JSON.stringify(data,null,2));
}

exports.run = products;


...