=====Erste Erfahrungen mit Electron / NodeJS und der Anbindung an die Oracle Datenbank==== **Ziel:** Die Oracle Datenbank mit dem JavaScipt / NodeSJS [[https://electronjs.org|Electron]] unter Windows ansprechen. Fazit nach dem ersten Tests: Das mag ja ganz gut und einfach in der richtigen Konfiguration und mit den richtigen Treibern an der richtigen Stelle in der richtigen Version funktionieren. ABER für ein Produkt ist das wohl nicht so einfach geeignet, bei verschiedenen Kunden alle diese Abhängigkeiten sicherzustellen ist bestimmt eine Herausforderung. Schade, im Prinzip eine interessante Technologie, wie oft aber im Oracle Umfeld wenig Praxis tauglich. Da bleibt nur die Alternative den DB Konnect gleich ganz als Rest Service zu implementieren, dann fällt dieser Treiber Krampf weg. Das ist dann aber wieder nix für eine kleine, schnelle Lösung ohne viel Aufwand. demnächst mehr - dies ist nur eine reine Stoffsammlung bis es zum erstenmal auch klappt, bisher ein böses Treiber Problem. ---- ==== Vorbereitung - Software Installation ==== == Editor für JavaScript == Editor https://code.visualstudio.com/, ist ja die gleiche Architektur, sehr zu empfehlendes Werkzeug. == NodeJS == Download über => https://nodejs.org/en/ Standard Installation == Demo Applikation als Rahmen für das Ganze == Nach der NodeJS Installation kann mit dem Packet Manager von NodeJS alles nach geladen werden. Demo Applikation von https://electronjs.org/docs/tutorial/first-app#trying-this-example git clone https://github.com/electron/electron-quick-start cd electron-quick-start # Install dependencies npm install # Run the app npm start npm install electron --save-dev == Oracle Instant Client 12c + .Net Runtime 13 == Für den Oracle NodeJS einen Instanclient 64 bit + die .Net Runtime 13 installiert. siehe => http://www.oracle.com/technetwork/database/database-technologies/instant-client/overview/index.html ==Oracle oracledb NodeJS Trieber installieren== npm install oracledb siehe auch https://github.com/oracle/node-oracledb === Alternativ unter Linux === https://nodejs.org/en/download/package-manager/ Oracle Linux 7 curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - yum -y install nodejs Download RPM von http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html yum install oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm orcledb npm install oracledb Demo App yum install git cd /srv git clone https://github.com/electron/electron-quick-start cd electron-quick-start # Install dependencies npm install # oracle and yquery npm install oracledb npm install jquery # Run the app npm start /srv/electron-quick-start/node_modules/electron/dist/electron: error while loading shared libraries: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory yum install gtk2 /srv/electron-quick-start/node_modules/electron/dist/electron: error while loading shared libraries: libXtst.so.6: cannot open shared object file: No such file or directory yum install libXtst /srv/electron-quick-start/node_modules/electron/dist/electron: error while loading shared libraries: libXss.so.1: cannot open shared object file: No such file or directory yum install libXScrnSaver /srv/electron-quick-start/node_modules/electron/dist/electron: error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory yum provides */libgconf-2.so.4 yum install GConf2 ... npm ERR! Failed at the electron-quick-start@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. .. ? xForwarding war nicht aktiv Nächster Fehler libGL error: unable to load driver: swrast_dri.so libGL error: failed to load driver: swrast yum install mesa-dri-drivers Danach wird aber kein Text mehr im fenster angezeit! yum erase mesa-dri-drivers Nun kann Text wieder dargestellt werden .... Hmm ... das mag mich nicht der nächste Fehler Uncaught Error: NJS-045: cannot load the oracledb add-on binary for Node.js 8.2.1 (linux, x64) Cannot load /srv/electron-quick-start/node_modules/oracledb/build/Release/oracledb.node The module '/srv/electron-quick-start/node_modules/oracledb/build/Release/oracledb.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 59. This version of Node.js requires NODE_MODULE_VERSION 57. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`).Uncaught Error: NJS-045: cannot load the oracledb add-on binary for Node.js 8.2.1 (linux, x64) Cannot load /srv/electron-quick-start/node_modules/oracledb/build/Release/oracledb.node The module '/srv/electron-quick-start/node_modules/oracledb/build/Release/oracledb.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 59. This version of Node.js requires NODE_MODULE_VERSION 57. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`). # Auf ältere Nodejs Version 8.2 zurück gegangen # neu installiert npm install oracledb export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib # alternativ sh -c "echo /usr/lib/oracle/12.2/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf" ldconfig Jetzt geht es! => Unter Linux funktioniert es! Unter Windows muss ich wohl noch weiter forschen was da nicht klappt. ---- ==== Umsetzung des ersten Hello Worlds ==== Code Beispiel für das Auslesen der EMP Tabelle: // sleep time expects milliseconds function sleep (time) { return new Promise((resolve) => setTimeout(resolve, time)); } // einbinden var oracledb = require('oracledb'); /* Test mit einer normalen Connection oracledb.getConnection( { user : "gpi", password : "gpi", connectString : "10.10.10.1/GPI" }, function(err, connection) { if (err) { console.error(err); return; } connection.execute( "select sysdate || ' --- Result ' from dual ", function(err, result) { if (err) { console.error(err); return; } console.log(result.rows); }); }); */ console.log("-- Info -- try to init oracle -"); // Pool Function oracledb.createPool ( { user : "gpi", password : "gpi", connectString : "10.10.10.1/GPI" }, function(err, pool) { if (err) console.error(err); else { console.log("-- Info :: Pool Alias ::"+ pool.poolAlias); // 'default' } } ); console.log("-- Info -- Try to geht the pool-"); var pool = null; // Create Pool is not syncron, we have to wait! -- oracledb.getPool('default'); // Usage! sleep(500).then(() => { pool = oracledb.getPool('default'); pool._logStats(); $sql="select ename from emp where empno = :ID "; pool.getConnection(function(err, conn) { conn.execute( $sql, [7839], // bind value for :id { outFormat: oracledb.OBJECT }, function(err, result) { if (err) { console.error(err.message); return; } console.log(result.rows); // $('#resultDiv').text("SQL Script Aufruf "+rows[0].ename ); }); }); }); Test mit node: PS C:\entwicklung\electronjs\electron-quick-start> node .\renderer.js -- Info -- try to init oracle - -- Info -- Try to geht the pool- -- Info :: Pool Alias ::default Pool statistics not enabled [ { ENAME: 'KING' } ] Bis her hat es allerdings noch nicht geklappt, unter NodeJS wird alles richtig erkannt, aber in Electron wird behaupted der DDL's für den Treiber werden nicht gefunden. Nach dem Start von Electron (nmp start) kann mit CTRL+Shift+I die Debug Konsole gestartet werden. Der Fehler: Uncaught Error: NJS-045: cannot load the oracledb add-on binary for Node.js 8.2.1 (win32, x64) Cannot load C:\entwicklung\electronjs\electron-quick-start\node_modules\oracledb\build\Release\oracledb.node A dynamic link library (DLL) initialization routine failed. \\?\C:\entwicklung\electronjs\electron-quick-start\node_modules\oracledb\build\Release\oracledb.node Als nächstes Teste ich das unter Linux. == JQuery == // Jquery installieren npm install jquery --save //verwenden ==== Quellen ==== oracledb * Listenpunkthttps://blogs.oracle.com/opal/introducing-node-oracledb-a-nodejs-driver-for-oracle-database Wrapper für den oracledb : * https://www.npmjs.com/package/simple-oracledb **Electron** * Beispiel: https://electronjs.org/docs/tutorial/first-app#trying-this-example * https://netodeolino.github.io/2016/09/17/Creating-a-Desktop-application-with-the-Electron-js/ Zu NodeJs: * Websocket Beispiel https://www.doag.org/formes/servlet/DocNavi?action=getFile&did=9545332&key=JobMpLfDZKrtJ9iUE2h Oracle Jet: * https://icodealot.com/oracle-jet-native-apps-with-electron-and-node-js/ * http://www.oracle.com/webfolder/technetwork/jet/jetCookbook.html Visual Code Extension * https://code.visualstudio.com/docs/extensions/overview