dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

Move to synchronous `db.load` #598

Open twolfson opened 9 years ago

twolfson commented 9 years ago

Inside of db.load, there is no reason for it to be an asynchronous function. We should make it synchronous and deprecate the cb functionality.

db.load(__dirname + '/path/to/models.js');
dxg commented 9 years ago

I agree. I don't use .load personally, and load models my own way:

files = "model1 model2 model3".split(' ');
for (var i = 0; i < files.length; i++) {
  require("./" + files[i])(orm, db);
}
rainabba commented 9 years ago

If the models only load once and can't be used until they've loaded, synchronous (blocking) actually makes sense here. If the app requires the DB, then instead of having to check if it's initialized in every call, I'd rather block during app load. I'm facing a similar issue with another ORM.