Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oracle

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oracle - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

2

package.json

@@ -6,3 +6,3 @@ {

"homepage": "https://github.com/nearinfinity/node-oracle",
"version": "0.3.1",
"version": "0.3.2",
"engines": {

@@ -9,0 +9,0 @@ "node": ">=0.6.0"

@@ -24,36 +24,84 @@ # Install

# Example
# Examples
The simplest way to connect to the database uses the following code:
```javascript
var oracle = require("oracle");
oracle.connect({ "hostname": "localhost", "user": "test", "password": "test" }, function(err, connection) {
// selecting rows
connection.execute("SELECT * FROM person WHERE name = :1", ['bob smith'], function(err, results) {
// results will be an array of objects
var connectData = { "hostname": "localhost", "user": "test", "password": "test", "database": "ORCL" };
oracle.connect(connectData, function(err, connection) {
...
connection.close(); // call this when you are done with the connection
});
});
```
The `database` parameter contains the "service name" or "SID" of the database. If you have an Oracle RAC or some other kind of setup, or if you prefer to use "TNS", you can do so as well. You can either provide a complete connection string, like:
// inserting with return value
connection.execute(
"INSERT INTO person (name) VALUES (:1) RETURNING id INTO :2",
['joe ferner', new oracle.OutParam()],
function(err, results) {
// results.updateCount = 1
// results.returnParam = the id of the person just inserted
});
```javascript
var connString =
"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))";
```
or just the shortcut as declared in your `tnsnames.ora`:
DEV =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
The connection parameter would then be:
```javascript
var connectData = { "tns": "DEV", "user": "test", "password": "test" };
// or: var connectData = { "tns": connString, "user": "test", "password": "test" };
```
To access a table you could then use:
```javascript
oracle.connect(connData, function(err, connection) {
connection.setAutoCommit(true);
connection.commit(function(err) {
// transaction committed
});
// selecting rows
connection.execute("SELECT * FROM person", [], function(err, results) {
if ( err ) {
console.log(err);
} else {
console.log(results);
connection.rollback(function(err) {
// transaction rolledback
// inserting with return value
connection.execute(
"INSERT INTO person (name) VALUES (:1) RETURNING id INTO :2",
['joe ferner', new oracle.OutParam()],
function(err, results) {
if ( err ) { console.log(err) } else {
console.log(results);
}
// results.updateCount = 1
// results.returnParam = the id of the person just inserted
connection.close(); // call this when you are done with the connection
}
);
}
});
connection.close(); // call this when you are done with the connection
});
```
To validate whether the connection is still established after some time:
```javascript
if (! connection.isConnected()) {
// retire this connection from a pool
}
```
## Out Params

@@ -60,0 +108,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc