SlideShare uma empresa Scribd logo
1 de 48
Baixar para ler offline
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Oracle Developer
Node.js und die Oracle-Datenbank
Carsten Czarski
Business Unit Database
Oracle Deutschland B.V. & Co KG
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Inhalt
• Node.js: Was ist das
• Der Treiber für die Oracle-Datenbank: node-oracledb
• Node.js und die Oracle-Datenbank am Beispiel
– 1: Zugriff auf eine Tabelle und Ausgabe auf der Konsole
– 2: Ausgabe von Tabellendaten als JSON über HTTP
– 3: Mail-Listener: Automatisches Laden von Mails in Tabellen
– 4: WebSockets meets Oracle Database
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Node.js
Node.js is an open source, cross-platform runtime environment for server-side and
networking applications. Node.js applications are written in JavaScript, and can be run
within the Node.js runtime.
Node.js provides an event-driven architecture and a non-blocking I/O API that optimizes
an application's throughput and scalability. These technologies are commonly used for
real-time web applications.
Node.js uses the Google V8 JavaScript engine to execute code, and a large percentage of
the basic modules are written in JavaScript. Node.js contains a built-in library to allow
applications to act as a Web server without software such as Apache HTTP Server or IIS.
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Javascript auf dem Server
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Node.js ...
• ... basiert auf der Google V8 Engine (JavaScript)
– Open Source seit 2008
– Implementiert in C++
– Kompiliert Javascript mit einem Just In Time Compiler
• ... ist asynchron und eventgetrieben
– I/O-Gebundene API Calls sind nicht-blockierend
– Entwickler übergibt eine Callback-Funktion
– Interne Verwendung einer Event Queue
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Klassischer (synchroner) Programmablauf
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Asynchroner Programmablauf mit node.js
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Node Packaged Modules (npm)
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Populäre node.js Pakete
• Express: HTTP Server
• MailListener: Liest Mails aus einem IMAP/POP Postfach aus
• Websockets: Server für HTML5 Websocket-Technologie
• Webshot: HTML-Seiten abrufen und als Bild speichern
• Node-Oracledb: Oracle-Datenbanktreiber für node.js
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
node-oracledb
• node.js Treiber für die Oracle-Datenbank
– "Offizieller" Treiber für die Oracle-Datenbank
– Derzeit verfügbar: Version 0.2 (Early Adopter)
– Produktionsversion wird 1.0 sein
• Features
– SQL and PL/SQL Execution, Binding using JavaScript objects or arrays, Query results as
JavaScript objects or array, Conversion between JavaScript and Oracle types
– Transaction Management, Connection Pooling, Statement Caching, Client Result
Caching, End-to-end tracing
– High Availability Features: Fast Application Notification (FAN), Runtime Load
Balancing (RLB), Transparent Application Failover (TAF)
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Download von GitHub
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Voraussetzung: Python muss installiert sein
• Version zwischen 2.5 und 3.0
$ python2.7
Python 2.7.9 (default, Jan 29 2015, 17:33:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Installation node.js und node-oracledb
ZIP-Archive
auspacken
Node.js
testen
Build node-
oracledb
Umgebung
vorbereiten
Erstes
Programm
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Voraussetzungen – Linux-System
• Download und Auspacken der ZIP-Archive
• $ORACLE_HOMEOracle Instant Client (Basic + SDK)
• $NODE_HOMENode.js
• $NODE_ORACLEDB_HOMENode-oracledb
$ ls
instantclient_12_1 node-v0.10.36-linux-x64 node-oracledb-master
$
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Installation node.js und node-oracledb
ZIP-Archive
auspacken
Node.js
testen
Build node-
oracledb
Umgebung
vorbereiten
Erstes
Programm
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Node.js installieren und einrichten
• Starten von node.js mit "$NODE_HOME/bin/node"
• Starten des Paketmanagers npm mit "$NODE_HOME/bin/node"
$ cd $NODE_HOME
$ ls
bin ChangeLog include lib LICENSE node_modules README.md share
$ ls ./bin
node npm
$ $NODE_HOME/bin/node -v
v0.10.36
$ $NODE_HOME/bin/npm -v
1.4.28
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Proxy-Server und Umgebungsvariablen
• Falls Node.js Umgebung hinter der Firewall
• Package Manager braucht Internetverbindung
$ export PATH=$NODE_HOME/bin:$PATH
$ npm config set proxy=http://{proxy-server}:{port}
$ npm config set https-proxy=http://{proxy-server}:{port}
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Installation node.js und node-oracledb
ZIP-Archive
auspacken
Node.js
testen
Build node-
oracledb
Umgebung
vorbereiten
Erstes
Programm
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Oracle Instant Client installieren
• Verzeichnisstruktur nach Auspacken des ZIP-Archivs
$ cd $ORACLE_HOME
$ find
.
./uidrvci
./libocci.so.12.1
./libociei.so
:
./xstreams.jar
./sdk
./sdk/include
./sdk/include/occiCommon.h
./sdk/include/occi.h
./sdk/include/occiData.h
:
Instantclient
"BASIC"
Instantclient
"SDK"
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Umgebung für Build von "node-oracledb" vorbereiten
• Symlink erzeugen
• Umgebungsvariablen setzen
$ ls $ORACLE_HOME/libcntsh.*
libclntshcore.so.12.1 libclntsh.so.12.1
$ ln –s libclntsh.so.12.1 libclntsh.so
$ ls
libclntshcore.so.12.1 libclntsh.so libclntsh.so.12.1
$ export OCI_LIB_DIR = $ORACLE_HOME # Einmalig für Build
$ export OCI_INC_DIR = $ORACLE_HOME/sdk/include # Einmalig für Build
$ export LD_LIBRARY_PATH = $ORACLE_HOME:$LD_LIBRARY_PATH # Immer nötig
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Build von "node-oracledb"
$ cd $NODE_ORACLEDB_HOME
$ npm install
> oracledb@0.2.4 install /home/oracle/node-oracledb-master
> node-gyp rebuild
make: Entering directory `/home/oracle/node-oracledb-master/build'
CXX(target) Release/obj.target/oracledb/src/njs/src/njsOracle.o
CXX(target) Release/obj.target/oracledb/src/njs/src/njsPool.o
CXX(target) Release/obj.target/oracledb/src/njs/src/njsConnection.o
CXX(target) Release/obj.target/oracledb/src/njs/src/njsMessages.o
CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiEnv.o
CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiEnvImpl.o
CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiException.o
CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiExceptionImpl.o
CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiConnImpl.o
CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiDateTimeArrayImpl.o
CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiPoolImpl.o
CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiStmtImpl.o
CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiUtils.o
SOLINK_MODULE(target) Release/obj.target/oracledb.node
SOLINK_MODULE(target) Release/obj.target/oracledb.node: Finished
COPY Release/oracledb.node
make: Leaving directory `/home/oracle/node-oracledb-master/build'
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Installation node.js und node-oracledb
ZIP-Archive
auspacken
Node.js
testen
Build node-
oracledb
Umgebung
vorbereiten
Erstes
Programm
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Arbeitsumgebung erzeugen
• $ mkdir /home/oracle/nodework
• $ cd /home/oracle/nodework
• $ mkdir node_modules
• $ cd node_modules
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
"node-oracledb" nach "node_modules" verschieben
• $ mkdir /home/oracle/nodework
• $ cd /home/oracle/nodework
• $ mkdir node_modules
• $ cd node_modules
• $ mv $NODE_ORACLEDB_HOME .
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
"node-oracledb" nach "node_modules" verschieben
• $ mkdir /home/oracle/nodework
• $ cd /home/oracle/nodework
• $ mkdir node_modules
• $ cd node_modules
• $ mv $NODE_ORACLEDB_HOME .
• $ mv node-oracledb-master oracledb
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Installation node.js und node-oracledb
ZIP-Archive
auspacken
Node.js
testen
Build node-
oracledb
Umgebung
vorbereiten
Erstes
Programm
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Das erste "node-oracledb" Programm: emp.js
var oracledb = require('oracledb');
oracledb.getConnection(
{
user : "scott",
password : "tiger",
connectString : "sccloud033:1521/orcl"
},
function(err, connection) {
if (err) {console.error(err.message); return;}
connection.execute(
"SELECT * from EMP where EMPNO=7839",
[],
function(err, result) {
if (err) {console.log('%s', err.message); return;}
console.log(result.rows);
}
);
});
console.log("Finished – really?");
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Verzeichnisstruktur
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Test: Das erste Node.js Programm
$ node emp.js
Finished. Really????
[ [ 7839,
'KING',
'PRESIDENT',
null,
Tue Nov 17 1981 00:00:00 GMT+0100 (CET),
5000,
null,
10 ] ]
$
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Zweites Programm: "JSON-HTTP-Server"
var oracledb = require('oracledb');
var http = require('http');
oracledb.createPool(
{
user : "scott",
password : "tiger",
connectString : "sccloud033:1521/orcl",
poolMin : 1,
poolMax : 20
},
function(err, pool){
if (err) { ... }
http.createServer(function (req, res) {
pool.getConnection(function(err, connection){
if (err) { ... }
connection.execute("select * from emp ", [], function(err, results) {
if (err) { ... }
connection.release(function (err) {
if (err) { ... }
});
res.writeHead(200, {'Content-Type': 'application/json'});!
res.end(JSON.stringify(results.rows));
})
})
}).listen(1234, 'sccloud033.de.oracle.com')
});
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Zweites Programm: "JSON-HTTP-Server"
var oracledb = require('oracledb');
var http = require('http');
oracledb.createPool(
{
user : "scott",
password : "tiger",
connectString : "sccloud033:1521/orcl",
poolMin : 1,
poolMax : 20
},
function(err, pool){
if (err) { ... }
http.createServer(function (req, res) {
pool.getConnection(function(err, connection){
if (err) { ... }
connection.execute("select * from emp ", [], function(err, results) {
if (err) { ... }
connection.release(function (err) {
if (err) { ... }
});
res.writeHead(200, {'Content-Type': 'application/json'});!
res.end(JSON.stringify(results.rows));
})
})
}).listen(1234, 'sccloud033.de.oracle.com')
});
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Verzeichnisstruktur nach "npm install express"
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Express: Einfacher Webserver
var express = require('express')
function startServer () {
var app = express();
app.get ("/emp/*", processEmp);
app.get ("/dept/*", processDept);
var server = app.listen(9000, function () {
var host = server.address().address
var port = server.address().port
console.log('Table EMP REST Service listening at http://%s:%s', host, port);
});
}
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Express: Einfacher Webserver
function processEmp(req, res) {
pool.getConnection(function(err, connection){
connection.execute(
"select * from emp where (empno=:1 or :1 is null)",
[req.params[0]],
function(err, results) {
connection.release(function (err) {}),
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(results.rows));
}
)
})
}
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Ein wichtiger Tipp zwischendurch ...
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
IMAP Integration: Mail Listener
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Verzeichnisstruktur nach "npm install mail-listener2"
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
MailListener2: IMAP-Server mit Tabelle verbinden
var mailListener = new MailListener({
username: "vorname.nachname@mycompany.com",
password: "***********",
host: "mailserver.mycompany.com",
port: 993,
tls: true,
tlsOpTions: { rejectUnauthorized: false },
mailbox: "INBOX",
searchFilter: ["UNSEEN"],
markSeen: true,
fetchUnreadOnStart: false,
mailParserOptions: {streamAttachments: true},
attachments: false
});
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
MailListener2: IMAP-Server mit Tabelle verbinden
mailListener.on("mail", function(mail, seqno, attributes) {
if (mail.subject.match(/^MAIL_NODETEST.*/)) {
pool.getConnection(function(err, connection){
connection.execute(
"insert into mails_nodejs (sender, subject, datetime) values (:1, :2, :3)",
[mail.from[0].address, mail.subject, mail.date],
function(err, results) {
if (err) { console.log(err); }
connection.commit(function (err) {…});
connection.release(function (err) {…});
console.log("storing message: "" + mail.subject + """);
}
)
})
} else {
console.log("Ignoring Message: ""+mail.subject+""");
}
});
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
HTML5-Websocket: Asynchrone Client-Benachrichtigung
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
HTML5 Websockets
• Bidirektionale Verbindung zwischen Browser und Webserver
– Browser sendet HTTP-Anfrage mit Upgrade Request für Websocket
– Verbindung bleibt nach Server-Antwort offen
– Server kann weitere Daten ohne erneute Client-Anfrage senden
• Nutzen
– Gut geeignet für jede Form der asynchronen Benachrichtigung
– Ständiges Polling des Clients zum Server fällt weg
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
HTML5 Websockets im Internet
Internet erfordert
viele offene
Websockets
Leichtgewichtige
Server-Technologie
nötig
Node.js
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
HTML5 Websockets mit Node.js
DEMO
Oracle Confidential – 4
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Weitere Informationen
• Node.js Info und Download
http://nodejs.org
• Node Package Manager
http://npmjs.org
• Oracle-Treiber node-oracledb auf Github
https://github.com/oracle/node-oracledb
• Node.js Developer Center im OTN
http://www.oracle.com/technetwork/database/database-technologies/node_js/oracle-node-js-2399407.html
• Diskussionsforum node.js und Oracle
https://community.oracle.com/community/database/developer-tools/node_js/content
Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
Carsten.Czarski@oracle.com
http://tinyurl.com/apexcommunity
http://sql-plsql-de.blogspot.com
http://plsqlexecoscomm.sourceforge.net
http://plsqlmailclient.sourceforge.net
Twitter: @cczarski @oraclebudb
Nächster Oracle Developer Monthly
20. Februar 2015 – 09:00 Uhr

Mais conteúdo relacionado

Mais procurados

GitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by ScalaGitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by Scala
takezoe
 
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur! Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
David Delabassee
 

Mais procurados (20)

Spark zeppelin-cassandra at synchrotron
Spark zeppelin-cassandra at synchrotronSpark zeppelin-cassandra at synchrotron
Spark zeppelin-cassandra at synchrotron
 
Elasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English versionElasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English version
 
GitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by ScalaGitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by Scala
 
From zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and ElasticsearchFrom zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and Elasticsearch
 
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur! Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
 
Nashorn: JavaScript Running on Java VM (English)
Nashorn: JavaScript Running on Java VM (English)Nashorn: JavaScript Running on Java VM (English)
Nashorn: JavaScript Running on Java VM (English)
 
How to build your query engine in spark
How to build your query engine in sparkHow to build your query engine in spark
How to build your query engine in spark
 
Battle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchBattle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearch
 
JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?
 
Configuration for Java EE and the Cloud
Configuration for Java EE and the CloudConfiguration for Java EE and the Cloud
Configuration for Java EE and the Cloud
 
Configuration with Apache Tamaya
Configuration with Apache TamayaConfiguration with Apache Tamaya
Configuration with Apache Tamaya
 
Oracle REST Data Services: POUG Edition
Oracle REST Data Services: POUG EditionOracle REST Data Services: POUG Edition
Oracle REST Data Services: POUG Edition
 
Configuration for Java EE: Config JSR and Tamaya
Configuration for Java EE: Config JSR and TamayaConfiguration for Java EE: Config JSR and Tamaya
Configuration for Java EE: Config JSR and Tamaya
 
Data stax academy
Data stax academyData stax academy
Data stax academy
 
Supercharge your Code to get optimal Database Performance
Supercharge your Code to get optimal Database PerformanceSupercharge your Code to get optimal Database Performance
Supercharge your Code to get optimal Database Performance
 
Nashorn in the future (English)
Nashorn in the future (English)Nashorn in the future (English)
Nashorn in the future (English)
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache Tamaya
 
Clogeny Hadoop ecosystem - an overview
Clogeny Hadoop ecosystem - an overviewClogeny Hadoop ecosystem - an overview
Clogeny Hadoop ecosystem - an overview
 
Creating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at ScaleCreating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at Scale
 

Destaque

Greg Mohr Portfolio 1997-2004
Greg Mohr Portfolio 1997-2004Greg Mohr Portfolio 1997-2004
Greg Mohr Portfolio 1997-2004
Greg Mohr
 
Selfies auf Instagram, Pinterest und Snapchat
Selfies auf Instagram, Pinterest und SnapchatSelfies auf Instagram, Pinterest und Snapchat
Selfies auf Instagram, Pinterest und Snapchat
pechakucha1
 
JÖBSTL Firmenvorstellung 2016 (DE)
JÖBSTL Firmenvorstellung 2016 (DE)JÖBSTL Firmenvorstellung 2016 (DE)
JÖBSTL Firmenvorstellung 2016 (DE)
Atanas Vassilev
 
Norwich Estates
Norwich EstatesNorwich Estates
Norwich Estates
Karl Amc
 

Destaque (16)

TIK KELAS 9 BAB 2
TIK KELAS 9 BAB 2TIK KELAS 9 BAB 2
TIK KELAS 9 BAB 2
 
Gefuehle
GefuehleGefuehle
Gefuehle
 
Greg Mohr Portfolio 1997-2004
Greg Mohr Portfolio 1997-2004Greg Mohr Portfolio 1997-2004
Greg Mohr Portfolio 1997-2004
 
Bisnode Branchenreport Maschinenbau 2014
Bisnode Branchenreport Maschinenbau 2014Bisnode Branchenreport Maschinenbau 2014
Bisnode Branchenreport Maschinenbau 2014
 
Danke prinzipessa
Danke prinzipessaDanke prinzipessa
Danke prinzipessa
 
Präsentation plug in development
Präsentation plug in developmentPräsentation plug in development
Präsentation plug in development
 
Selfies auf Instagram, Pinterest und Snapchat
Selfies auf Instagram, Pinterest und SnapchatSelfies auf Instagram, Pinterest und Snapchat
Selfies auf Instagram, Pinterest und Snapchat
 
Prn1
Prn1Prn1
Prn1
 
JÖBSTL Firmenvorstellung 2016 (DE)
JÖBSTL Firmenvorstellung 2016 (DE)JÖBSTL Firmenvorstellung 2016 (DE)
JÖBSTL Firmenvorstellung 2016 (DE)
 
Norwich Estates
Norwich EstatesNorwich Estates
Norwich Estates
 
TIK KELAS 9 BAB 2
TIK KELAS 9 BAB 2TIK KELAS 9 BAB 2
TIK KELAS 9 BAB 2
 
Wovor fürchten sich deutsche Manager? Über 130 Führungskräfte geben Auskunft
Wovor fürchten sich deutsche Manager? Über 130 Führungskräfte geben AuskunftWovor fürchten sich deutsche Manager? Über 130 Führungskräfte geben Auskunft
Wovor fürchten sich deutsche Manager? Über 130 Führungskräfte geben Auskunft
 
SALES FOLDER_BCN
SALES FOLDER_BCNSALES FOLDER_BCN
SALES FOLDER_BCN
 
bc.prace_LK_final
bc.prace_LK_finalbc.prace_LK_final
bc.prace_LK_final
 
Halbzeit!
Halbzeit! Halbzeit!
Halbzeit!
 
Sojola: Blogger Relations, Blog & Website
Sojola: Blogger Relations, Blog & WebsiteSojola: Blogger Relations, Blog & Website
Sojola: Blogger Relations, Blog & Website
 

Semelhante a Node.js und die Oracle-Datenbank

Project Avatar (Lyon JUG & Alpes JUG - March 2014)
Project Avatar (Lyon JUG & Alpes JUG  - March 2014)Project Avatar (Lyon JUG & Alpes JUG  - March 2014)
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
David Delabassee
 

Semelhante a Node.js und die Oracle-Datenbank (20)

Core os dna_automacon
Core os dna_automaconCore os dna_automacon
Core os dna_automacon
 
Extending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.jsExtending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.js
 
Core os dna_oscon
Core os dna_osconCore os dna_oscon
Core os dna_oscon
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 
Java in a world of containers
Java in a world of containersJava in a world of containers
Java in a world of containers
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
Oracle application container cloud back end integration using node final
Oracle application container cloud back end integration using node finalOracle application container cloud back end integration using node final
Oracle application container cloud back end integration using node final
 
Killer Docker Workflows for Development
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for Development
 
Ruby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingRuby on Rails All Hands Meeting
Ruby on Rails All Hands Meeting
 
Webinar: Creating an Effective Docker Build Pipeline for Java Apps
Webinar: Creating an Effective Docker Build Pipeline for Java AppsWebinar: Creating an Effective Docker Build Pipeline for Java Apps
Webinar: Creating an Effective Docker Build Pipeline for Java Apps
 
Server Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David DelabasseeServer Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David Delabassee
 
Pushing JavaEE outside of the enterprise: Home Automation & IoT - David Delab...
Pushing JavaEE outside of the enterprise: Home Automation & IoT - David Delab...Pushing JavaEE outside of the enterprise: Home Automation & IoT - David Delab...
Pushing JavaEE outside of the enterprise: Home Automation & IoT - David Delab...
 
Docker module 1
Docker module 1Docker module 1
Docker module 1
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Dockerizing Oracle Database
Dockerizing Oracle Database Dockerizing Oracle Database
Dockerizing Oracle Database
 
Wicked Easy Ceph Block Storage & OpenStack Deployment with Crowbar
Wicked Easy Ceph Block Storage & OpenStack Deployment with CrowbarWicked Easy Ceph Block Storage & OpenStack Deployment with Crowbar
Wicked Easy Ceph Block Storage & OpenStack Deployment with Crowbar
 
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
Project Avatar (Lyon JUG & Alpes JUG  - March 2014)Project Avatar (Lyon JUG & Alpes JUG  - March 2014)
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
 
Intro to Sails.js
Intro to Sails.jsIntro to Sails.js
Intro to Sails.js
 

Último

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Último (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 

Node.js und die Oracle-Datenbank

  • 1. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Oracle Developer Node.js und die Oracle-Datenbank Carsten Czarski Business Unit Database Oracle Deutschland B.V. & Co KG
  • 2. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Inhalt • Node.js: Was ist das • Der Treiber für die Oracle-Datenbank: node-oracledb • Node.js und die Oracle-Datenbank am Beispiel – 1: Zugriff auf eine Tabelle und Ausgabe auf der Konsole – 2: Ausgabe von Tabellendaten als JSON über HTTP – 3: Mail-Listener: Automatisches Laden von Mails in Tabellen – 4: WebSockets meets Oracle Database
  • 3. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Node.js Node.js is an open source, cross-platform runtime environment for server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime. Node.js provides an event-driven architecture and a non-blocking I/O API that optimizes an application's throughput and scalability. These technologies are commonly used for real-time web applications. Node.js uses the Google V8 JavaScript engine to execute code, and a large percentage of the basic modules are written in JavaScript. Node.js contains a built-in library to allow applications to act as a Web server without software such as Apache HTTP Server or IIS.
  • 4. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Javascript auf dem Server
  • 5. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Node.js ... • ... basiert auf der Google V8 Engine (JavaScript) – Open Source seit 2008 – Implementiert in C++ – Kompiliert Javascript mit einem Just In Time Compiler • ... ist asynchron und eventgetrieben – I/O-Gebundene API Calls sind nicht-blockierend – Entwickler übergibt eine Callback-Funktion – Interne Verwendung einer Event Queue
  • 6. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Klassischer (synchroner) Programmablauf
  • 7. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Asynchroner Programmablauf mit node.js
  • 8. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Node Packaged Modules (npm)
  • 9. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Populäre node.js Pakete • Express: HTTP Server • MailListener: Liest Mails aus einem IMAP/POP Postfach aus • Websockets: Server für HTML5 Websocket-Technologie • Webshot: HTML-Seiten abrufen und als Bild speichern • Node-Oracledb: Oracle-Datenbanktreiber für node.js
  • 10. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. node-oracledb • node.js Treiber für die Oracle-Datenbank – "Offizieller" Treiber für die Oracle-Datenbank – Derzeit verfügbar: Version 0.2 (Early Adopter) – Produktionsversion wird 1.0 sein • Features – SQL and PL/SQL Execution, Binding using JavaScript objects or arrays, Query results as JavaScript objects or array, Conversion between JavaScript and Oracle types – Transaction Management, Connection Pooling, Statement Caching, Client Result Caching, End-to-end tracing – High Availability Features: Fast Application Notification (FAN), Runtime Load Balancing (RLB), Transparent Application Failover (TAF)
  • 11. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Download von GitHub
  • 12. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Voraussetzung: Python muss installiert sein • Version zwischen 2.5 und 3.0 $ python2.7 Python 2.7.9 (default, Jan 29 2015, 17:33:10) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
  • 13. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Installation node.js und node-oracledb ZIP-Archive auspacken Node.js testen Build node- oracledb Umgebung vorbereiten Erstes Programm
  • 14. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Voraussetzungen – Linux-System • Download und Auspacken der ZIP-Archive • $ORACLE_HOMEOracle Instant Client (Basic + SDK) • $NODE_HOMENode.js • $NODE_ORACLEDB_HOMENode-oracledb $ ls instantclient_12_1 node-v0.10.36-linux-x64 node-oracledb-master $
  • 15. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Installation node.js und node-oracledb ZIP-Archive auspacken Node.js testen Build node- oracledb Umgebung vorbereiten Erstes Programm
  • 16. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Node.js installieren und einrichten • Starten von node.js mit "$NODE_HOME/bin/node" • Starten des Paketmanagers npm mit "$NODE_HOME/bin/node" $ cd $NODE_HOME $ ls bin ChangeLog include lib LICENSE node_modules README.md share $ ls ./bin node npm $ $NODE_HOME/bin/node -v v0.10.36 $ $NODE_HOME/bin/npm -v 1.4.28
  • 17. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Proxy-Server und Umgebungsvariablen • Falls Node.js Umgebung hinter der Firewall • Package Manager braucht Internetverbindung $ export PATH=$NODE_HOME/bin:$PATH $ npm config set proxy=http://{proxy-server}:{port} $ npm config set https-proxy=http://{proxy-server}:{port}
  • 18. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Installation node.js und node-oracledb ZIP-Archive auspacken Node.js testen Build node- oracledb Umgebung vorbereiten Erstes Programm
  • 19. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Oracle Instant Client installieren • Verzeichnisstruktur nach Auspacken des ZIP-Archivs $ cd $ORACLE_HOME $ find . ./uidrvci ./libocci.so.12.1 ./libociei.so : ./xstreams.jar ./sdk ./sdk/include ./sdk/include/occiCommon.h ./sdk/include/occi.h ./sdk/include/occiData.h : Instantclient "BASIC" Instantclient "SDK"
  • 20. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Umgebung für Build von "node-oracledb" vorbereiten • Symlink erzeugen • Umgebungsvariablen setzen $ ls $ORACLE_HOME/libcntsh.* libclntshcore.so.12.1 libclntsh.so.12.1 $ ln –s libclntsh.so.12.1 libclntsh.so $ ls libclntshcore.so.12.1 libclntsh.so libclntsh.so.12.1 $ export OCI_LIB_DIR = $ORACLE_HOME # Einmalig für Build $ export OCI_INC_DIR = $ORACLE_HOME/sdk/include # Einmalig für Build $ export LD_LIBRARY_PATH = $ORACLE_HOME:$LD_LIBRARY_PATH # Immer nötig
  • 21. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Build von "node-oracledb" $ cd $NODE_ORACLEDB_HOME $ npm install > oracledb@0.2.4 install /home/oracle/node-oracledb-master > node-gyp rebuild make: Entering directory `/home/oracle/node-oracledb-master/build' CXX(target) Release/obj.target/oracledb/src/njs/src/njsOracle.o CXX(target) Release/obj.target/oracledb/src/njs/src/njsPool.o CXX(target) Release/obj.target/oracledb/src/njs/src/njsConnection.o CXX(target) Release/obj.target/oracledb/src/njs/src/njsMessages.o CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiEnv.o CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiEnvImpl.o CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiException.o CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiExceptionImpl.o CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiConnImpl.o CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiDateTimeArrayImpl.o CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiPoolImpl.o CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiStmtImpl.o CXX(target) Release/obj.target/oracledb/src/dpi/src/dpiUtils.o SOLINK_MODULE(target) Release/obj.target/oracledb.node SOLINK_MODULE(target) Release/obj.target/oracledb.node: Finished COPY Release/oracledb.node make: Leaving directory `/home/oracle/node-oracledb-master/build'
  • 22. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Installation node.js und node-oracledb ZIP-Archive auspacken Node.js testen Build node- oracledb Umgebung vorbereiten Erstes Programm
  • 23. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Arbeitsumgebung erzeugen • $ mkdir /home/oracle/nodework • $ cd /home/oracle/nodework • $ mkdir node_modules • $ cd node_modules
  • 24. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. "node-oracledb" nach "node_modules" verschieben • $ mkdir /home/oracle/nodework • $ cd /home/oracle/nodework • $ mkdir node_modules • $ cd node_modules • $ mv $NODE_ORACLEDB_HOME .
  • 25. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. "node-oracledb" nach "node_modules" verschieben • $ mkdir /home/oracle/nodework • $ cd /home/oracle/nodework • $ mkdir node_modules • $ cd node_modules • $ mv $NODE_ORACLEDB_HOME . • $ mv node-oracledb-master oracledb
  • 26. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Installation node.js und node-oracledb ZIP-Archive auspacken Node.js testen Build node- oracledb Umgebung vorbereiten Erstes Programm
  • 27. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Das erste "node-oracledb" Programm: emp.js var oracledb = require('oracledb'); oracledb.getConnection( { user : "scott", password : "tiger", connectString : "sccloud033:1521/orcl" }, function(err, connection) { if (err) {console.error(err.message); return;} connection.execute( "SELECT * from EMP where EMPNO=7839", [], function(err, result) { if (err) {console.log('%s', err.message); return;} console.log(result.rows); } ); }); console.log("Finished – really?");
  • 28. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Verzeichnisstruktur
  • 29. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Test: Das erste Node.js Programm $ node emp.js Finished. Really???? [ [ 7839, 'KING', 'PRESIDENT', null, Tue Nov 17 1981 00:00:00 GMT+0100 (CET), 5000, null, 10 ] ] $
  • 30. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Zweites Programm: "JSON-HTTP-Server" var oracledb = require('oracledb'); var http = require('http'); oracledb.createPool( { user : "scott", password : "tiger", connectString : "sccloud033:1521/orcl", poolMin : 1, poolMax : 20 }, function(err, pool){ if (err) { ... } http.createServer(function (req, res) { pool.getConnection(function(err, connection){ if (err) { ... } connection.execute("select * from emp ", [], function(err, results) { if (err) { ... } connection.release(function (err) { if (err) { ... } }); res.writeHead(200, {'Content-Type': 'application/json'});! res.end(JSON.stringify(results.rows)); }) }) }).listen(1234, 'sccloud033.de.oracle.com') });
  • 31. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Zweites Programm: "JSON-HTTP-Server" var oracledb = require('oracledb'); var http = require('http'); oracledb.createPool( { user : "scott", password : "tiger", connectString : "sccloud033:1521/orcl", poolMin : 1, poolMax : 20 }, function(err, pool){ if (err) { ... } http.createServer(function (req, res) { pool.getConnection(function(err, connection){ if (err) { ... } connection.execute("select * from emp ", [], function(err, results) { if (err) { ... } connection.release(function (err) { if (err) { ... } }); res.writeHead(200, {'Content-Type': 'application/json'});! res.end(JSON.stringify(results.rows)); }) }) }).listen(1234, 'sccloud033.de.oracle.com') });
  • 32. Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
  • 33. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Verzeichnisstruktur nach "npm install express"
  • 34. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Express: Einfacher Webserver var express = require('express') function startServer () { var app = express(); app.get ("/emp/*", processEmp); app.get ("/dept/*", processDept); var server = app.listen(9000, function () { var host = server.address().address var port = server.address().port console.log('Table EMP REST Service listening at http://%s:%s', host, port); }); }
  • 35. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Express: Einfacher Webserver function processEmp(req, res) { pool.getConnection(function(err, connection){ connection.execute( "select * from emp where (empno=:1 or :1 is null)", [req.params[0]], function(err, results) { connection.release(function (err) {}), res.writeHead(200, {'Content-Type': 'application/json'}); res.end(JSON.stringify(results.rows)); } ) }) }
  • 36. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Ein wichtiger Tipp zwischendurch ...
  • 37. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. IMAP Integration: Mail Listener
  • 38. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Verzeichnisstruktur nach "npm install mail-listener2"
  • 39. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. MailListener2: IMAP-Server mit Tabelle verbinden var mailListener = new MailListener({ username: "vorname.nachname@mycompany.com", password: "***********", host: "mailserver.mycompany.com", port: 993, tls: true, tlsOpTions: { rejectUnauthorized: false }, mailbox: "INBOX", searchFilter: ["UNSEEN"], markSeen: true, fetchUnreadOnStart: false, mailParserOptions: {streamAttachments: true}, attachments: false });
  • 40. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. MailListener2: IMAP-Server mit Tabelle verbinden mailListener.on("mail", function(mail, seqno, attributes) { if (mail.subject.match(/^MAIL_NODETEST.*/)) { pool.getConnection(function(err, connection){ connection.execute( "insert into mails_nodejs (sender, subject, datetime) values (:1, :2, :3)", [mail.from[0].address, mail.subject, mail.date], function(err, results) { if (err) { console.log(err); } connection.commit(function (err) {…}); connection.release(function (err) {…}); console.log("storing message: "" + mail.subject + """); } ) }) } else { console.log("Ignoring Message: ""+mail.subject+"""); } });
  • 41. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. HTML5-Websocket: Asynchrone Client-Benachrichtigung
  • 42. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. HTML5 Websockets • Bidirektionale Verbindung zwischen Browser und Webserver – Browser sendet HTTP-Anfrage mit Upgrade Request für Websocket – Verbindung bleibt nach Server-Antwort offen – Server kann weitere Daten ohne erneute Client-Anfrage senden • Nutzen – Gut geeignet für jede Form der asynchronen Benachrichtigung – Ständiges Polling des Clients zum Server fällt weg
  • 43. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. HTML5 Websockets im Internet Internet erfordert viele offene Websockets Leichtgewichtige Server-Technologie nötig Node.js
  • 44. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. HTML5 Websockets mit Node.js DEMO Oracle Confidential – 4
  • 45. Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
  • 46. Copyright © 2014 Oracle and/or its affiliates. All rights reserved.
  • 47. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Weitere Informationen • Node.js Info und Download http://nodejs.org • Node Package Manager http://npmjs.org • Oracle-Treiber node-oracledb auf Github https://github.com/oracle/node-oracledb • Node.js Developer Center im OTN http://www.oracle.com/technetwork/database/database-technologies/node_js/oracle-node-js-2399407.html • Diskussionsforum node.js und Oracle https://community.oracle.com/community/database/developer-tools/node_js/content
  • 48. Copyright © 2014 Oracle and/or its affiliates. All rights reserved. Carsten.Czarski@oracle.com http://tinyurl.com/apexcommunity http://sql-plsql-de.blogspot.com http://plsqlexecoscomm.sourceforge.net http://plsqlmailclient.sourceforge.net Twitter: @cczarski @oraclebudb Nächster Oracle Developer Monthly 20. Februar 2015 – 09:00 Uhr