think-model
Advanced tools
Comparing version 1.0.1 to 1.0.2
10
index.js
@@ -25,4 +25,5 @@ const helper = require('think-helper'); | ||
config = helper.parseAdapterConfig(modelConfig, config); | ||
config.cache = helper.parseAdapterConfig(cacheConfig, config.cache); | ||
return model(name, config, m); | ||
const instance = model(name, config, m); | ||
instance._cacheConfig = cacheConfig; | ||
return instance; | ||
} | ||
@@ -46,5 +47,6 @@ | ||
config = helper.parseAdapterConfig(this.config('model'), config); | ||
const instance = model(name, config, m); | ||
// add adapter cache config | ||
config.cache = helper.parseAdapterConfig(this.config('cache'), config.cache); | ||
return model(name, config, m); | ||
instance._cacheConfig = this.config('cache'); | ||
return instance; | ||
} | ||
@@ -51,0 +53,0 @@ } |
@@ -96,2 +96,3 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
instance.models = this.models; | ||
instance._cacheConfig = this._cacheConfig; | ||
return instance; | ||
@@ -106,5 +107,3 @@ } | ||
cache(key, config) { | ||
if (key === undefined) { | ||
return this; | ||
} | ||
if (key === undefined) return this; | ||
if (!helper.isString(key)) { | ||
@@ -116,7 +115,13 @@ [key, config] = ['', key]; | ||
} | ||
const options = helper.parseAdapterConfig(this.config.cache, config); | ||
if (!options.key) { | ||
options.key = key; | ||
const cacheConfig = this._cacheConfig; | ||
if (cacheConfig) { | ||
config = helper.parseAdapterConfig(cacheConfig, this.config.cache, config); | ||
} else { | ||
config = helper.parseAdapterConfig(this.config.cache, config); | ||
} | ||
this.options.cache = options; | ||
if (!config.key) { | ||
config.key = key; | ||
} | ||
assert(helper.isFunction(config.handle), 'cache.handle must be a function'); | ||
this.options.cache = config; | ||
return this; | ||
@@ -718,4 +723,15 @@ } | ||
} | ||
const fields = Object.keys(result); | ||
// result is empty | ||
if (fields.length === 0) { | ||
const multi = field.indexOf(',') > -1 && field.indexOf('(') === -1; | ||
if (multi) { | ||
field.split(/\s*,\s*/).forEach(function (item) { | ||
result[item] = []; | ||
}); | ||
return result; | ||
} else { | ||
return []; | ||
} | ||
} | ||
if (fields.length === 1) { | ||
@@ -722,0 +738,0 @@ return result[fields[0]]; |
{ | ||
"name": "think-model", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "An adapter-based ORM for ThinkJS 3.x", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -77,3 +77,3 @@ const {test} = require('ava'); | ||
test('model set cache option', t => { | ||
t.plan(5); | ||
t.plan(4); | ||
@@ -83,3 +83,4 @@ const model = new Model('post', { | ||
cache: { | ||
type: 'file' | ||
type: 'file', | ||
handle: () => {} | ||
} | ||
@@ -90,4 +91,2 @@ }); | ||
t.is(model.options.cache.timeout, 500); | ||
model.cache({type: 'session'}); | ||
t.is(model.options.cache.type, 'session'); | ||
model.cache('page', {timeout: 300}); | ||
@@ -94,0 +93,0 @@ t.is(model.options.cache.key, 'page'); |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
153094
5411
30