UPSERT (insert/update) extension to oracledb.
npm install oracledb-upsert      
> UPSERT (insert/update) extension to oracledb.
* Overview
* Usage
* Installation
* API Documentation
* Contributing
* Release History
* License
``js
//load the oracledb library
var oracledb = require('oracledb');
//load the simple oracledb
var SimpleOracleDB = require('simple-oracledb');
//modify the original oracledb library
SimpleOracleDB.extend(oracledb);
//load the extension
require('oracledb-upsert');
//from this point connections fetched via oracledb.getConnection(...) or pool.getConnection(...)
//have access to the UPSERT function.
oracledb.getConnection(function onConnection(error, connection) {
if (error) {
//handle error
} else {
//work with new capabilities or original oracledb capabilities
connection.upsert({
query: 'SELECT ID FROM MY_DATA WHERE ID = :id',
insert: 'INSERT INTO MY_DATA (ID, NAME) VALUES (:id, :name)',
update: 'UPDATE MY_DATA SET NAME = :name WHERE ID = :id'
}, {
id: 110,
name: 'new name'
}, {
autoCommit: false
}, function onUpsert(error, results) {
if (error) {
//handle error...
} else {
console.log('rows affected: ', results.rowsAffected);
//continue flow...
}
});
}
});
`
Example
`js
connection.upsert({
query: 'SELECT ID FROM MY_DATA WHERE ID = :id',
insert: 'INSERT INTO MY_DATA (ID, NAME) VALUES (:id, :name)',
update: 'UPDATE MY_DATA SET NAME = :name WHERE ID = :id'
}, {
id: 110,
name: 'new name'
}, {
autoCommit: false
}, function onUpsert(error, results) {
if (error) {
//handle error...
} else {
console.log('rows affected: ', results.rowsAffected);
//continue flow...
}
});
`
`sh``
npm install --save oracledb-upsert
This library doesn't define oracledb as a dependency and therefore it is not installed when installing oracledb-upsert.
You should define oracledb in your package.json and install it based on the oracledb installation instructions found at: installation guide
| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2020-05-13 | v2.0.0 | Migrate to github actions and upgrade minimal node version |
| 2019-02-08 | v1.2.1 | Maintenance |
| 2016-08-05 | v0.0.43 | Added promise support |
| 2016-03-04 | v0.0.1 | Initial release. |