...
For more information about RLA capabilities, see Record Level Access API.
To All you need to do to begin using RLA/SQL functions within your pjs programs :Create is to create the DbDefn module which . This module enables you to use RLA functions in lieu of writing a whole lot of sql
, and it also allows for database independence.
To create a module we need to be able to name and describe some key parts of that table (or view/logical).
- Module File name --> example product.DbDefn.js
- The module file name must end with .DbDefn.js
- The first part of the name "product" is how your pjs program(s) will reference it.
- Describing the table:
- useSQL - optional required - Set this to true if you want this to enable RLA/SQL functionality, else it will use the IBM i RLA functionality
- dbObject - required - Set this to the actual database object name, can be the name of a table or a view..
- dbSchema - optional - Set this to the actual database schema
- format - optional - When converting RPG programs to Profoundjs programs this is required. This is the record format name of the IBM i table.
- uniqueKey - required - uniqueKey - required - This is needed to be able to read 1 record at a time in a uniquely specific sequence.
- field - the name of the column
- ascending: true or false if the column should be sorted in ascending order
- dbSchema - optional - Set this to the actual database schema
- format - optional - When converting RPG programs to Profoundjs programs this is required. This is the record format name of the IBM i table.
- overrides - optional - this is where you can override specific fields types and values
- There are several reasons for using this. Here are a few:
- The database does not support storage of that type of field (such as a Time type field)
- The database stores 2 separate fields for Date and Time, but you want to put them together as a single DateTime field
- You have choose to store date or time values as string, but you want the UI to show them as true dates and times.
- There are several reasons for using this. Here are a few:
...
Below is an example of that PRODUCT table and was placed . It was placed directly under the modules folder. It . If you have a lot of tables, you will want to better organize them.
This example also shows a couple different examples on how you can use the overriseoverride.
- 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 had a pjs program you don't have to do anything to it, as long as it does not use any of the unsupported functions.
...