db2Model

所属分类:数据库系统
开发工具:JavaScript
文件大小:0KB
下载次数:0
上传日期:2020-07-09 16:58:13
上 传 者sh-1993
说明:  Db2用于i型发生器,
(Db2 for i model generator,)

文件列表:
.vscode/ (0, 2020-07-09)
.vscode/launch.json (539, 2020-07-09)
LICENSE (35103, 2020-07-09)
db2.js (548, 2020-07-09)
index.js (1597, 2020-07-09)
lib/ (0, 2020-07-09)
lib/GenericTable.js (3605, 2020-07-09)
lib/ModelGenerator.js (1644, 2020-07-09)
lib/ProcGroup.js (5808, 2020-07-09)
lib/table.js (8262, 2020-07-09)
package-lock.json (895, 2020-07-09)
package.json (397, 2020-07-09)
test.js (2774, 2020-07-09)

# db2Model db2Model is a model generator for Db2 for i tables. It's a simple command line tool that generates JavaScript classes which can be used as a simple ORM. db2Model can create: * a class for the table specified * static methods to fetch a row based on the primary or unique keys * instance methods to fetch models based on foreign references keys * instance methods to update and delete based on primary or unique keys * classes for tables referenced in foreign keys. * documentation for each class, instance method and static method. * a class with methods to call stored procedures for a chosen schema db2Model is using the odbc driver to connect, which must be installed onto the system running this script. ## Usage ### Creating Models ``` $ node index models SAMPLE DEPARTMENT The following environment variabes are needed to connect: ISYS, IUSER, IPASS Connecting to xxx with xxx. Defined table DEPARTMENT Defined table EMPLOYEE Written to "models/Department.js". Written to "models/Employee.js". ``` The reason `Employee.js` is created here is because the `DEPARTMENT` table has the column `mgrno` which references to the `EMPLOYEE` table. It also creates `getEmployee` inside of the `Employee` class as you can see below. ```js const Department = require('./models/Department.js'); const SupportDept = await Department.Get('E01'); assert(SupportDept.deptname === "SUPPORT SERVICES"); const ParentDept = await SupportDept.getDepartment(); assert(ParentDept.deptno === "A00"); //getEmployee returns an Employee class const SupportManager = await SupportDept.getEmployee(); assert(SupportManager.firstnme === 'JOHN'); ``` After you have generated your Models you can easily change the class properties without affecting the way the data is retrieved - which is great if you mostly have short-name columns. ### Created procedure classes db2Model can create classes with methods to call stored procedures in a chosen schema. This example generates functions for calling all stored procedures in QSYS - even though most of them are useless to regular developers. ``` $ node index procs QSYS The following environment variabes are needed to connect: ISYS, IUSER, IPASS Connecting to seiden.iinthecloud.com with alan3. (node:6642) Warning: N-API is an experimental feature and could change at any time. Fetching columns for QSYS/CREATE_SQL_SAMPLE. Fetching columns for QSYS/CREATE_XML_SAMPLE. ... Written to "models/QSYS.js". ``` And is now callable like so: ```js const QSYS = require('./models/QSYS.js'); try { await QSYS.create_sql_sample("SAMPLE"); } catch (e) { console.log('Sample tables may already exist in SAMPLE schema.'); } ``` ## Tests There is a simple unit test provided. The test will try to create the Db2 for i sample tables in the `SAMPLE` schema. ``` > node test.js The following environment variabes are needed to connect: ISYS, IUSER, IPASS Connecting to xxx with xxx. Sample tables may already exist in SAMPLE schema. Defined table DEPARTMENT Defined table EMPLOYEE Written to "models/Department.js". Written to "models/Employee.js". Tests pass ```

近期下载者

相关文件


收藏者