{"id":17002026,"url":"https://github.com/sagiegurari/oracledb-upsert","last_synced_at":"2025-04-12T06:21:43.900Z","repository":{"id":5426648,"uuid":"53056011","full_name":"sagiegurari/oracledb-upsert","owner":"sagiegurari","description":"UPSERT (insert/update) extension to oracledb","archived":false,"fork":false,"pushed_at":"2023-01-19T17:37:03.000Z","size":145,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T01:41:31.548Z","etag":null,"topics":["database","nodejs","oracle","oracle-db","upsert"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagiegurari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-03T14:23:27.000Z","updated_at":"2021-10-27T10:06:24.000Z","dependencies_parsed_at":"2023-02-11T13:00:22.497Z","dependency_job_id":null,"html_url":"https://github.com/sagiegurari/oracledb-upsert","commit_stats":null,"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Foracledb-upsert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Foracledb-upsert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Foracledb-upsert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Foracledb-upsert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagiegurari","download_url":"https://codeload.github.com/sagiegurari/oracledb-upsert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525775,"owners_count":21118750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","nodejs","oracle","oracle-db","upsert"],"created_at":"2024-10-14T04:26:53.056Z","updated_at":"2025-04-12T06:21:43.877Z","avatar_url":"https://github.com/sagiegurari.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oracledb-upsert\n\n[![NPM Version](http://img.shields.io/npm/v/oracledb-upsert.svg?style=flat)](https://www.npmjs.org/package/oracledb-upsert) [![CI](https://github.com/sagiegurari/oracledb-upsert/workflows/CI/badge.svg?branch=master)](https://github.com/sagiegurari/oracledb-upsert/actions) [![Coverage Status](https://coveralls.io/repos/sagiegurari/oracledb-upsert/badge.svg)](https://coveralls.io/r/sagiegurari/oracledb-upsert) [![Known Vulnerabilities](https://snyk.io/test/github/sagiegurari/oracledb-upsert/badge.svg)](https://snyk.io/test/github/sagiegurari/oracledb-upsert) [![Inline docs](http://inch-ci.org/github/sagiegurari/oracledb-upsert.svg?branch=master)](http://inch-ci.org/github/sagiegurari/oracledb-upsert) [![License](https://img.shields.io/npm/l/oracledb-upsert.svg?style=flat)](https://github.com/sagiegurari/oracledb-upsert/blob/master/LICENSE) [![Total Downloads](https://img.shields.io/npm/dt/oracledb-upsert.svg?style=flat)](https://www.npmjs.org/package/oracledb-upsert)\n\n\u003e UPSERT (insert/update) extension to oracledb.\n\n* [Overview](#overview)\n* [Usage](#usage)\n* [Installation](#installation)\n* [API Documentation](docs/api.md)\n* [Contributing](.github/CONTRIBUTING.md)\n* [Release History](#history)\n* [License](#license)\n\n\u003ca name=\"overview\"\u003e\u003c/a\u003e\n## Overview\nThis library extends the oracledb connection object with a new upsert function to enable to run UPDATE or INSERT based on the\ndata currently in the DB.\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n## Usage\nIn order to use this library, you need to extend the main oracledb object as follows:\n\n```js\n//load the oracledb library\nvar oracledb = require('oracledb');\n\n//load the simple oracledb\nvar SimpleOracleDB = require('simple-oracledb');\n\n//modify the original oracledb library\nSimpleOracleDB.extend(oracledb);\n\n//load the extension\nrequire('oracledb-upsert');\n\n//from this point connections fetched via oracledb.getConnection(...) or pool.getConnection(...)\n//have access to the UPSERT function.\noracledb.getConnection(function onConnection(error, connection) {\n    if (error) {\n        //handle error\n    } else {\n        //work with new capabilities or original oracledb capabilities\n        connection.upsert({\n            query: 'SELECT ID FROM MY_DATA WHERE ID = :id',\n            insert: 'INSERT INTO MY_DATA (ID, NAME) VALUES (:id, :name)',\n            update: 'UPDATE MY_DATA SET NAME = :name WHERE ID = :id'\n        }, {\n            id: 110,\n            name: 'new name'\n        }, {\n            autoCommit: false\n        }, function onUpsert(error, results) {\n            if (error) {\n                //handle error...\n            } else {\n                console.log('rows affected: ', results.rowsAffected);\n\n                //continue flow...\n            }\n        });\n    }\n});\n```\n\n\u003ca name=\"connection-upsert\"\u003e\u003c/a\u003e\n\u003c!-- markdownlint-disable MD009 MD031 MD036 --\u003e\n### 'connection.upsert(sqls, bindParams, [options], [callback]) ⇒ [Promise]'\nThe UPSERT oracledb extension gets 3 SQL statements.\u003cbr\u003e\nIt first queries the database for existing data, based on the output, it either runs INSERT or UPDATE SQL.\u003cbr\u003e\nIf it runs the INSERT and it fails on unique constraint, it will also run the UPDATE.\u003cbr\u003e\nThe output in the callback is the output of the INSERT/UPDATE operation.\n\n**Example**  \n```js\nconnection.upsert({\n  query: 'SELECT ID FROM MY_DATA WHERE ID = :id',\n  insert: 'INSERT INTO MY_DATA (ID, NAME) VALUES (:id, :name)',\n  update: 'UPDATE MY_DATA SET NAME = :name WHERE ID = :id'\n}, {\n  id: 110,\n  name: 'new name'\n}, {\n  autoCommit: false\n}, function onUpsert(error, results) {\n  if (error) {\n    //handle error...\n  } else {\n    console.log('rows affected: ', results.rowsAffected);\n\n    //continue flow...\n  }\n});\n```\n\u003c!-- markdownlint-enable MD009 MD031 MD036 --\u003e\n\n\u003ca name=\"installation\"\u003e\u003c/a\u003e\n## Installation\nIn order to use this library, just run the following npm install command:\n\n```sh\nnpm install --save oracledb-upsert\n```\n\nThis library doesn't define oracledb as a dependency and therefore it is not installed when installing oracledb-upsert.\u003cbr\u003e\nYou should define oracledb in your package.json and install it based on the oracledb installation instructions found at: [installation guide](https://github.com/oracle/node-oracledb/blob/master/INSTALL.md)\n\n## API Documentation\nSee full docs at: [API Docs](docs/api.md)\n\n## Contributing\nSee [contributing guide](.github/CONTRIBUTING.md)\n\n\u003ca name=\"history\"\u003e\u003c/a\u003e\n## Release History\n\n| Date        | Version | Description |\n| ----------- | ------- | ----------- |\n| 2020-05-13  | v2.0.0  | Migrate to github actions and upgrade minimal node version |\n| 2019-02-08  | v1.2.1  | Maintenance |\n| 2016-08-05  | v0.0.43 | Added promise support |\n| 2016-03-04  | v0.0.1  | Initial release. |\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n## License\nDeveloped by Sagie Gur-Ari and licensed under the Apache 2 open source license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagiegurari%2Foracledb-upsert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagiegurari%2Foracledb-upsert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagiegurari%2Foracledb-upsert/lists"}