Skip to content

Commit

Permalink
Fix _create for oracledb client (#221)
Browse files Browse the repository at this point in the history
The _create  method was throwing an error because oracledb insert was returning the counting of changed rows instead of an array with row inserted rows id. The fix consists in adding a clause to set the "returning" parameter of insert to ["id"].
  • Loading branch information
lucas-portela authored and daffl committed Sep 4, 2019
1 parent 2315230 commit 6531441
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,22 @@ class Service extends AdapterService {
}).catch(errorHandler);
}

_create (data, params = {}) {
_create(data, params = {}) {
if (Array.isArray(data)) {
return Promise.all(data.map(current => this._create(current, params)));
}

const returning = this.db(params).client.config.client === 'pg' ? [this.id] : [];
const client = this.db(params).client.config.client;
const returning = client === "pg" || client === "oracledb" ? [this.id] : [];

return this.db(params).insert(data, returning).then(rows => {
const id = data[this.id] !== undefined ? data[this.id] : rows[0];
return this.db(params)
.insert(data, returning)
.then(rows => {
const id = data[this.id] !== undefined ? data[this.id] : rows[0];

return this._get(id, params);
}).catch(errorHandler);
return this._get(id, params);
})
.catch(errorHandler);
}

_patch (id, raw, params = {}) {
Expand Down

0 comments on commit 6531441

Please sign in to comment.