@soinlabs/db
Advanced tools
Comparing version 1.2.0-alpha.3 to 1.2.0-alpha.4
@@ -20,3 +20,3 @@ const AbstractEntityInstance = require('./AbstractEntityInstance') | ||
const data = await this._model.create(values, newOptions) | ||
return this._parseToModelInstance(data, newOptions) | ||
return this.parseToModelInstance(data, newOptions) | ||
} | ||
@@ -27,3 +27,3 @@ | ||
const [data, created] = await this._model.upsert(values, newOptions) | ||
return [this._parseToModelInstance(data, newOptions), created] | ||
return [this.parseToModelInstance(data, newOptions), created] | ||
} | ||
@@ -34,3 +34,3 @@ | ||
const data = await this._model.bulkCreate(values, newOptions) | ||
return data.map(d => this._parseToModelInstance(d, newOptions)) | ||
return data.map(d => this.parseToModelInstance(d, newOptions)) | ||
} | ||
@@ -47,5 +47,5 @@ | ||
? data[1] | ||
? this._parseToModelInstance(data[1], newOptions) | ||
? this.parseToModelInstance(data[1], newOptions) | ||
: null | ||
: data[1].map(d => this._parseToModelInstance(d, newOptions)) | ||
: data[1].map(d => this.parseToModelInstance(d, newOptions)) | ||
) | ||
@@ -65,3 +65,3 @@ } | ||
const data = await this._model.findAll(newOptions) | ||
return data.map(d => this._parseToModelInstance(d, newOptions)) | ||
return data.map(d => this.parseToModelInstance(d, newOptions)) | ||
} | ||
@@ -74,3 +74,3 @@ | ||
...data, | ||
rows: data.rows.map(d => this._parseToModelInstance(d, newOptions)), | ||
rows: data.rows.map(d => this.parseToModelInstance(d, newOptions)), | ||
} | ||
@@ -107,3 +107,3 @@ } | ||
const data = await this._model.findOne(newOptions) | ||
return this._parseToModelInstance(data, newOptions) | ||
return this.parseToModelInstance(data, newOptions) | ||
} | ||
@@ -133,3 +133,3 @@ | ||
_parseToModelInstance(model, options) { | ||
parseToModelInstance(model, options) { | ||
if (options && options.raw) { | ||
@@ -136,0 +136,0 @@ return model |
@@ -10,3 +10,3 @@ const AbstractEntity = require('../abstract/AbstractEntity') | ||
_parseToModelInstance(model, options) { | ||
parseToModelInstance(model, options) { | ||
return model ? new MockEntityInstance(model, options) : model | ||
@@ -13,0 +13,0 @@ } |
@@ -13,2 +13,3 @@ /* eslint-disable global-require */ | ||
const MockEntity = require('../common/mock/MockEntity') | ||
const SequelizeEntity = require('../sequelize/SequelizeEntity') | ||
@@ -330,4 +331,19 @@ class DbOrm { | ||
} | ||
parseToModelInstance(entityName, values, options) { | ||
const entity = this._entities[entityName] | ||
if (!entity) { | ||
throw new Error(`Entity ${entityName} not found`) | ||
} | ||
return entity.parseToModelInstance( | ||
entity instanceof SequelizeEntity | ||
? entity.getModel().build(values) | ||
: values, | ||
options | ||
) | ||
} | ||
} | ||
module.exports = DbOrm |
@@ -11,3 +11,3 @@ const AbstractEntity = require('../common/abstract/AbstractEntity') | ||
_parseToModelInstance(model, options) { | ||
parseToModelInstance(model, options) { | ||
if (options && options.raw) { | ||
@@ -14,0 +14,0 @@ return model |
@@ -126,3 +126,3 @@ const AbstractEntity = require('../common/abstract/AbstractEntity') | ||
_parseToModelInstance(model, options) { | ||
parseToModelInstance(model, options) { | ||
if (options && options.raw) { | ||
@@ -129,0 +129,0 @@ return model |
@@ -727,3 +727,3 @@ const { | ||
...options, | ||
...(!options.include && { limit: 1 }), // TODO: Change this to buildQueryForFindOneDerivedTable | ||
limit: 1, | ||
fromFindOne: true, | ||
@@ -730,0 +730,0 @@ }) |
@@ -140,3 +140,3 @@ const _ = require('lodash') | ||
_parseToModelInstance(model, options) { | ||
parseToModelInstance(model, options) { | ||
if (options && options.raw) { | ||
@@ -143,0 +143,0 @@ return model |
{ | ||
"name": "@soinlabs/db", | ||
"version": "1.2.0-alpha.3", | ||
"version": "1.2.0-alpha.4", | ||
"main": "index.js", | ||
@@ -25,3 +25,3 @@ "repository": "", | ||
"@soinlabs/hawk": "^1.0.0", | ||
"@soinlabs/sybase": "^1.0.1", | ||
"@soinlabs/sybase": "^1.0.2", | ||
"compare-versions": "^6.1.0", | ||
@@ -28,0 +28,0 @@ "inflection": "^3.0.0", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
387670
160
11749
1
Updated@soinlabs/sybase@^1.0.2