node.js - Sequelize: Require vs Import -
They use the import function in documents for sequlize such as
// server File - like App.js var project = sequelize.import (__Deman + + "/ path / in / model / project") // Model definition / path / in / model / project.js // as you would like You can see, the datatype is very similar, explained above the module. Exchange = function (sequelize, datatype) {return sequels.define ("project", {name: datatype.STR, Description: datatype. TEXT}}}
However, what is wrong with it Will happen?
// in your server file - e.g. Requires App.js var project = (__dynamic + "/ path / per / model / project") // model definition / path / in / model / project.js var project = sequel .defen ("project", {Name: Sequelize.STRING, Description: Sequelize.TEXT}); Module.export = project
OK, as you can see that your model Two things are needed in definition: ; sequelize.import ('some') while using
This is similar to the requirement of (
('some') (this, sequential);
( this cecilize example)
Both are required to start their model, but the important thing to understand is That one of these is a classstep, so it is global, the second is an example and should be made with your connection parameters. / P>
So if you do this:
var project = sequelize.define ("Project", {name: Sequelize.STRING, Description: Sequelize.TEXT}); Module Exports = Project
Where does the sequel come from? It has to be passed immediately and in any way.
Here are the necessary examples instead of import:
// / path / to /app.js var Sequelize = require ('sequelize'); Var Sqlize = New Secquise (/ * ... * /); Var Project = Required ('/ path / from / model / project') (sequel, sequelize); // /path/to/models/project.js Module Exports = function (sequelize, datatype) {sequelize.define ("project", {name: datatype.STR, Description: datatype. TEXT}); }; Module.Exports = Project
You can also change it so that you do not have to pass sequelize due to its requirement in the model, but you will still need it < Before defining a / p>
Comments
Post a Comment