accessing your ibm i data from node.js and python · •api's are similar (behavior is...

43
IBM i テクニカル・ワークショップ 2016 © 2016 IBM Corporation Accessing your IBM i data from Node.js and Python Jesse R. Gorzinski, MBA [email protected] IBM i Emerging Solutions

Upload: others

Post on 03-Sep-2019

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

IBM i テクニカル・ワークショップ 2016

© 2016 IBM Corporation

Accessing your IBM idata from Node.js and Python

Jesse R. Gorzinski, MBA

[email protected]

IBM i Emerging Solutions

Page 2: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 3: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 4: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 5: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

direct connection via ibm_db (Python)

Page 6: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 7: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 8: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 9: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 10: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Access local or remote, any language, using simple XML scripts.

Page 11: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Access by REST web or DB2 stored procedures to XMLSERVICE.

Page 12: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Access XMLSERVICE public shared jobs (ctl='*here').

Page 13: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Access XMLSERVICE private jobs (ctl='*sbmjob', ipc='/tmp/unique').

Page 14: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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)

Page 15: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 16: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 17: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 18: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 19: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 20: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 21: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 22: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 23: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 24: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 25: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 26: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 27: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 28: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 29: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 30: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 31: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 32: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 33: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 34: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Page 35: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 36: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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);

});});

});

Page 37: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 38: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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!

Page 39: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 2016 IBM Corporation

IBM i テクニカル・ワークショップ 2016

Zend DBi from node-mysql (node.JS)

Page 40: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 41: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 42: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

© 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

Page 43: Accessing your IBM i data from Node.js and Python · •API's are similar (behavior is slightly different) •Package automatically detects you are running local, uses either DB2

Click to edit Master subtitle style

IBM i テクニカル・ワークショップ 2016

© 2016 IBM Corporation

Questions?