不要怂,就是干,撸起袖子干!

Commit f1e451e0 by Sushant Committed by GitHub

refactor: remove sequelize.import helper (#12175)

1 parent 541d2fac
......@@ -20,9 +20,11 @@ You should now use [cls-hooked](https://github.com/Jeff-Lewis/cls-hooked) packag
Sequelize.useCLS(namespace);
```
### Promise
### Sequelize
Bluebird has been removed. Public API now returns native promises. `Sequelize.Promise` is no longer available.
- Bluebird has been removed. Public API now returns native promises.
- `Sequelize.Promise` is no longer available.
- `sequelize.import` method has been removed.
### Model
......
......@@ -346,8 +346,6 @@ class Sequelize {
this.modelManager = new ModelManager(this);
this.connectionManager = this.dialect.connectionManager;
this.importCache = {};
Sequelize.runHooks('afterInit', this);
}
......@@ -463,38 +461,6 @@ class Sequelize {
}
/**
* Imports a model defined in another file. Imported models are cached, so multiple
* calls to import with the same path will not load the file multiple times.
*
* @tutorial https://github.com/sequelize/express-example
*
* @param {string} importPath The path to the file that holds the model you want to import. If the part is relative, it will be resolved relatively to the calling file
*
* @returns {Model} Imported model, returned from cache if was already imported
*/
import(importPath) {
// is it a relative path?
if (path.normalize(importPath) !== path.resolve(importPath)) {
// make path relative to the caller
const callerFilename = Utils.stack()[1].getFileName();
const callerPath = path.dirname(callerFilename);
importPath = path.resolve(callerPath, importPath);
}
if (!this.importCache[importPath]) {
let defineCall = arguments.length > 1 ? arguments[1] : require(importPath);
if (typeof defineCall === 'object') {
// ES6 module compatibility
defineCall = defineCall.default;
}
this.importCache[importPath] = defineCall(this, DataTypes);
}
return this.importCache[importPath];
}
/**
* Execute a query on the DB, optionally bypassing all the Sequelize goodness.
*
* By default, the function will return two arguments: an array of results, and a metadata object, containing number of affected rows etc.
......
......@@ -1224,28 +1224,6 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
});
});
describe('import', () => {
it('imports a dao definition from a file absolute path', function() {
const Project = this.sequelize.import('assets/project');
expect(Project).to.exist;
});
it('imports a dao definition with a default export', function() {
const Project = this.sequelize.import('assets/es6project');
expect(Project).to.exist;
});
it('imports a dao definition from a function', function() {
const Project = this.sequelize.import('Project', (sequelize, DataTypes) => {
return sequelize.define(`Project${parseInt(Math.random() * 9999999999999999, 10)}`, {
name: DataTypes.STRING
});
});
expect(Project).to.exist;
});
});
describe('define', () => {
it('raises an error if no values are defined', function() {
expect(() => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!