data-domain-driver
v0.2.1
Published
DDD: DataDomainDriver, Alternative **Legacy** Stored Procedures
Downloads
6
Readme
data-domain-driver
DDD: Data Domain Driver, Alternative **Legacy** Stored Procedures
Installation
$ # Configuration file and DDD definition file must be placed
$ npm install data-domain-driver
Quick Play
$ git clone https://github.com/nmrmsys/data-domain-driver.git
$ cd data-domain-driver
$ npm install
$ npm test
Basic Usage
// test.js
const DDD = new (require('data-domain-driver').DDD)();
returns = await DDD.callProcedure('proc01', params);
returns = await DDD.domain('another').callProcedure('procA', params);
DDD.end();
// proc01.js
const Procedure = require('data-domain-driver').Procedure;
Class proc01 extends Procedure {
async process(ddd, params, returns){
// sql-behind named SQL statement or raw SQL string can be specified
rs1 = await ddd.query('query1', {FLD1:'1', FLD2:'A'});
while(!rs1.EOF){
console.log(rs1.FLD1 + ', ' + rs1.FLD2 + ', ' + rs1.FLD3);
rs1.next();
}
await ddd.execute('stmt1', {FLD1:'1', FLD2:'A', FLD3:'zzz'});
ret1 = await ddd.callFunction('func01', params);
await ddd.database('mydb2').execute('stmt2', params);
rs2 = await ddd.database('webapi3').query('query2', params);
returns.result1 = rs1;
returns.result2 = rs2;
return 0; // returns.returnCode
}
}
-- proc01.sql
/**
* @name query1
* @desc Get data from TBL1
* @param :FLD1 - Search condition of FLD1
* @param :FLD2 - Search condition of FLD2
* @return TBL1 result set
*/
SELECT
FLD1
,FLD2
,FLD3
FROM TBL1
WHERE FLD1 = :FLD1
AND FLD2 = :FLD2
// func01.js
const Function = require('data-domain-driver').Function;
Class func01 extends Function {
async process(ddd, params, returns){
returns.resultA = params;
return 0; // returns.returnCode
}
}
One Table Query Builder
// procA.js
const Procedure = require('data-domain-driver').Procedure;
Class procA extends Procedure {
async process(ddd, params, returns){
// ddd.select(tblId, selClas, wheClas, ordClas, grpClas, havClas)
rs = await ddd.select('TBL1', ['FLD1', 'FLD2'], {FLD1: '2'}, 'FLD1');
// ddd.insert(tblId, insClas)
await ddd.insert('TBL1', {FLD1: '4', FLD2: 'D', FLD3: 'jkl'});
// ddd.update(tblId, updClas, wheClas)
await ddd.update('TBL1', {FLD1: '1x', FLD2: 'Ax'}, {FLD1: '1', FLD2: 'A'});
// ddd.delete(tblId, wheClas)
await ddd.delete('TBL1', {FLD1: '3', FLD2: 'C'});
// ddd.get(tblId, selClas, wheClas, ordClas, grpClas, havClas)
v = await ddd.get('TBL1', 'FLD2', {FLD1: '2'});
// ddd.set(tblId, setClas, wheClas)
await ddd.set('TBL1', {FLD2: 'D', FLD3: 'jkl'}, {FLD1: '4'});
return 0; // returns.returnCode
}
}
Dataset Anything Mapping
// test.js
const DDD = new (require('data-domain-driver').DDD)();
returns = await DDD.callProcedure('proc01', params);
DDD.end();
// DataSet.toJSON(
// mainDataDef - 'jsonName=dataName[keyName, ...]'
// ,relationDefs - {'relationName': 'dataName[keyName, ...]'}
// )
ordJson = returns.toJSON('orders=ORDER[ORDER_ID]', {'details': 'DETAIL[ORDER_ID]'});
// DataSet.toObject(
// mainDataDef - 'className=dataName[keyName, ...]'
// ,relationDefs - {'relationName': 'className=dataName[keyName, ...]'}
// )
ordObj = returns.toObject('Order=ORDER[ORDER_ID]', {'details': 'Detail=DETAIL[ORDER_ID]'});
// Order.js
const Model = require('data-domain-driver').Model;
module.exports = class Order extends Model {
// constructor(data){
// super(data);
// }
get data(){
return super.data;
}
set data(data){
super.data = data;
// Write custom data setting if needed
}
// Write domain logic here
}