Versions Compared

Key

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

...

  1. File name --> example product.DbDefn.js
    1. Important notes:The file name must end with .DbDefn.js
    2. The first part of the name "product" is how your pjs program will reference it :: "product"

 

Below is a simple table named PRODUCT that is keyed/ordered by a field called PRID.

 

 

...

    1. .
  1. Describing the table:
    1. useSQL - optional - Set this to true if you want this to enable RLA/SQL functionality, else it will use the IBM i RLA functionality
    2. dbObject - required - Set this to the actual database object name, can be the name of a table or a view.. 
    3. dbSchema - optional - Set this to the actual database schema
    4. format - optional - When converting RPG programs to Profoundjs programs this is required.  This is the record format name of the IBM i table.
    5. uniqueKey - required - This is needed to be able to read 1 record at a time in a uniquely specific sequence.
      1. field - the name of the column
      2. ascending: true or false if the column should be sorted in ascending order
    6. overrides - optional - this is where you can override specific fields types and values
      1. There are several reasons for using this.  Here are a few:
        1. The database does not support storage of that type of field (such as a Time type field)
        2. The database stores 2 separate fields for Date and Time, but you want to put them together as a single DateTime field
        3. You have choose to store date or time values as string, but you want the UI to show them as true dates and times.

** Important note: table names and field names are case sensitive **

 

Below is an example of that PRODUCT table and was placed under the modules folder.  It also shows a couple different examples on how you can use the overrise.

  • Field named "prcatid" that is stored in the database as character, but will be referenced within the pjs program as decimal.
  • Field name "prtime" that is stored in the database as character, but will be referenced with the pjs program 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() { return this.toString().padStart(5,"0") },
      transformFromDb: function() { return Number(this) },
    },
    prtime: {
      type: "time",
      transformToDb: profound.utils.timeToCharTransform,
      transformFromDb: profound.utils.charToTimeTransform
    }
  }
}

 

 

 

If you have an existing had a pjs program you don't have to do anything to it, as long as it does not use any of the non supported unsupported functions.

Here is a simple pjs program that reads all the records of a table.  It is just like any other pjs program using RLA.

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;