accessing your ibm i data from node.js and python · •api's are similar (behavior is...
TRANSCRIPT
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
Accessing your IBM idata from Node.js and Python
Jesse R. Gorzinski, MBA
IBM i Emerging Solutions
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Agenda
• Database access
– Direct database connectivity (ibm_db)
– IBM i toolkit (itoolkit package)
– Zend DBi
• Integrating with IBM i programs
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
ibm_db/ibm_db2 itoolkit MySQL
(Zend DBi)
Purpose in life direct DB2
connection
general purpose library
for commands, calling
*PGM/*SRVPGM's, SQL,
etc.
Allow MySQL
applications to use
MySQL on i
Install/Manage in a typical
scenario
language module language module
+
Apache
language module
+
Zend DBi
Lightning-fast performance
*(ONLY PYTHON HAS A DIRECT CALL
OPTION)
Call DB2 for i services
Run Existing MySQL-based
Applications
Access DB2 from another
partition or platform
(development or
deployment), or from IBM
BlueMix applications
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
direct connection via ibm_db/ibm_db2 packages
• Built on the DB2 Callable Level Interface (CLI) API's
• Provide the fastest performance
• Provides the most robust functionality
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
direct connection via ibm_db (Python)
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016DB2 Access for i
var db = require('/QOpenSys/QIBM/ProdData/Node/os400/db2i/lib/db2');db.init();db.conn("*LOCAL");db.exec("SELECT LSTNAM,CITY FROM QIWS.QCUSTCDT", function(result_set) {console.log(result_set);
});db.close();
[ { LSTNAM: 'Henning ', CITY: 'Dallas' },{ LSTNAM: 'Jones ', CITY: 'Clay ' },{ LSTNAM: 'Vine ', CITY: 'Broton' },{ LSTNAM: 'Johnson ', CITY: 'Helen ' },{ LSTNAM: 'Tyron ', CITY: 'Hector' },{ LSTNAM: 'Stevens ', CITY: 'Denver' }
. . .]
Results
- What: API set for DB2 database manipulation on IBM i- Location: /QOpenSys/QIBM/ProdData/Node/os400/db2i/
- Modules: bin/db2i.node and lib/db2.js
- No ORM yet. Best bet: github.com/balderdashy/waterline
Example
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
ibm_db/ibm_db2 itoolkit MySQL
(Zend DBi)
Purpose in life directDB2
connection
general purpose library
for commands, calling
*PGM/*SRVPGM's, SQL,
etc.
Allow MySQL
applications to use
MySQL on i
Install/Manage in a typical
scenario
language module language module
+
Apache
language module
+
Zend DBi
Lightning-fast performance
*(ONLY PYTHON HAS A DIRECT CALL
OPTION)
Call DB2 for i services
Run Existing MySQL-based
Applications
Access DB2 from another
partition or platform
(development or
deployment), or from IBM
BlueMix applications
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
itoolkit package for DB2 access
• Built on XMLSERVICE technology
• May require XMLSERVICE setup
• Available for all the popular open source languages
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Q: Where can I find XMLSERVICE?
A: RPG Open Source on YIPS …
http://youngiprofessionals.com/wiki/index.php/XMLSERVICE/XMLSERVICE
… or IBM i PTFs
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Access local or remote, any language, using simple XML scripts.
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Access by REST web or DB2 stored procedures to XMLSERVICE.
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Access XMLSERVICE public shared jobs (ctl='*here').
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Access XMLSERVICE private jobs (ctl='*sbmjob', ipc='/tmp/unique').
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Q: Does XMLSERVICE include REST interface?
A: Yes, RPG CGI XMLCGI included with download.
http://myibmi/cgi-bin/xmlcgi.pgm&db2=x@uid=x@pwd=x@ipc=x@ctl=x@xmlin=x@xmlout=x
/www/myweb/conf/httpd.conf:
ScriptAlias /cgi-bin/
/QSYS.LIB/XMLSERVICE.LIB/
<Directory /QSYS.LIB/XMLSERVICE.LIB/>
AllowOverride None
order allow,deny
allow from all
SetHandler cgi-script
Options +ExecCGI
</Directory>
REST parameters (GET/POST):
db2 - database (*LOCAL)
uid - user profile
pwd - profile password
ipc - IPC key name (/tmp/fred01)
ctl - CTL admin (see control)
xmlin - XML input (request)
xmlout – XML output size (bytes)
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Question and Answer …
Q: Does XMLSERVICE support complex IBM i calls?
A: Yes, very complex structures and system APIs.
http://youngiprofessionals.com/wiki/index.php/XMLSERVICE/XMLSERVICEQuick
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Ask any programmer …
Q: Does XMLSERVICE support DB2?
A: Yes, provides a rich XML based DB2 driver.
http://youngiprofessionals.com/wiki/index.php/XMLSERVICE/XMLSERVICEQuick
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
itoolkit packages
• All the capabilities of XMLService are surfaced through the itoolkit.
• Node.JS, Python, PHP, Ruby, all have very similar usage
• Examples here:
http://youngiprofessionals.com/wiki/index.php/XMLSERVICE/XMLSERVICE
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Call a *PGM
The itoolkit.js and
XMLSERVICE support much more
complex program calls and even go
beyond the PCML/Java Toolbox
limitations.
NOTE: This is 100% free-form
RPG, available in IBM i v7.1dcl-pr pgm1 extpgm;char1 char(1);dec1 packed(7:4);
end-pr;dcl-pi pgm1;char1 char(1);dec1 packed(7:4);
end-pi;
char1 = 'C';dec1 = 321.1234;return;
MYLIB/PGM1
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Invoke MYLIB/PGM1
var xt = require('/QOpenSys/QIBM/ProdData/Node/os400/xstoolkit/lib/itoolkit');var conn = new xt.iConn("*LOCAL");
var pgm = new xt.iPgm("PGM1", {"lib":"MYLIB"});pgm.addParam("","1A");pgm.addParam("0", "7p4");
conn.add(pgm.toXML());
conn.run(function (rsp) {var results = xt.xmlToJson(rsp);results.forEach(function(result, index){result.data.forEach(function(data, index2){console.log("type:" + data.type + " value:" + data.value);
});});
});
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
ibm_db/ibm_db2 itoolkit MySQL
(Zend DBi)
Purpose in life directDB2
connection
general purpose library
for commands, calling
*PGM/*SRVPGM's, SQL,
etc.
Allow MySQL
applications to use
MySQL on i
Install/Manage in a typical
scenario
language module language module
+
Apache
language module
+
Zend DBi
Lightning-fast performance
*(ONLY PYTHON HAS A DIRECT CALL
OPTION)
Call DB2 for i services
Run Existing MySQL-based
Applications
Access DB2 from another
partition or platform
(development or
deployment), or from IBM
BlueMix applications
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Zend DBi
• MySQL Server for IBM i
• Features a DB2 storage engine so that the data can be stored in DB2. It can
also be stored in a MySQL database
• Allows existing MySQL-based programs to talk to DB2
• Allows for MySQL development using packages such as PyMySQL (Python)
and node-mysql (Node.JS)
• Cannot call DB2 for i services
• MariaDB? Coming soon!
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
Zend DBi from node-mysql (node.JS)
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
ibm_db/ibm_db2 itoolkit MySQL
(Zend DBi)
Purpose in life directDB2
connection
general purpose library
for commands, calling
*PGM/*SRVPGM's, SQL,
etc.
Allow MySQL
applications to use
MySQL on i
Install/Manage in a typical
scenario
language module language module
+
Apache
language module
+
Zend DBi
Lightning-fast performance
*(ONLY PYTHON HAS A DIRECT CALL
OPTION)
Call DB2 for i services
Run Existing MySQL-based
Applications
Access DB2 from another
partition or platform
(development or
deployment), or from IBM
BlueMix applications
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
ibm_db/ibm_db2 from off-box?
• Leverage DB2 Connect to connect remotely to the database
• requires separate licensing
• API's are similar (behavior is slightly different)
• Package automatically detects you are running local, uses either DB2 direct-
call API's or DB2 Connect over TCP/IP
© 2016 IBM Corporation
IBM i テクニカル・ワークショップ 2016
ibm_db/ibm_db2 itoolkit MySQL
(Zend DBi)
Purpose in life directDB2
connection
general purpose library
for commands, calling
*PGM/*SRVPGM's, SQL,
etc.
Allow MySQL
applications to use
MySQL on i
Install/Manage in a typical
scenario
language module language module
+
Apache
language module
+
Zend DBi
Lightning-fast performance
*(ONLY PYTHON HAS A DIRECT CALL
OPTION)
Call DB2 for i services
Run Existing MySQL-based
Applications
Access DB2 from another
partition or platform
(development or
deployment), or from IBM
BlueMix applications
Click to edit Master subtitle style
IBM i テクニカル・ワークショップ 2016
© 2016 IBM Corporation
Questions?