javascript - How to organize models in a node.js website? -


I just node I started experimenting with creating a website using JS, and during the event of my model I have to face a problem.

The Mongoos are being used in all real world examples found on the Internet This library allows you to define your model in a steady manner. You can write it:

  // model / foo.js module.exports = ('Mongoose') is required. Model ('foo', ...); // app.js mongoose.connect (...); // some_controller_1.js var Foo = Requirement ('./Model / Foo'); Foo.find (...); // some_controller_2.js var Foo = Requirement ('./Model / Foo'); Foo.find (...);  

But since I do not want to use mongodbi, I need another ORM and I have not received any other ORM that I got this permission. You first need to create an example, and then only you can register your model. In addition, they do not allow access to the list of registered models.

So I tried to do this:

  // model / user.js var registration = []; Module Exports = function (sequelize) {var results = null; registration. For each (function (AMM) {if (elem.db == is the sequel) result = elem.value;}); If (Result) Return Results; // data definition word user = sequelize.define ("user", ...); Registration. Push ({db: sequelize, value: user}); Return user; };  

I can use it like this:

  // some_controller_1.js var Foo = require ('./mould / foo') ( App.get ('database')); Foo.find (...); //fu  

using

but on every single model file I have to write this small header and footer, a little disturbing and straight "you repeat" principle Besides, when there is no big issue, it is a memory leak because the "sequel" object will never be freed.

Is there a better way to do this, which I did not think about?

You can find an article about handling the model together with a sequel: < / P>

You basically just make a model / index.js as described here:

After that you just put your model definition inside the model model Here, as stated here:


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -