reload models

67 views
Skip to first unread message

jmls

unread,
Mar 9, 2015, 3:36:59 PM3/9/15
to loopb...@googlegroups.com
is there a way of reloading the models into app ? If I create a new .json and .js file, I want to be able to merge these new models into the system without having to restart the app itself.

Actually, I have the same question for data sources ? How can I reload the datasources if I've created a new db connection >

thanks

jmls

unread,
Aug 19, 2015, 11:26:28 AM8/19/15
to LoopbackJS
bump ;)

Has anyone got any idea on how to reload the models from within a running app ?

many thanks

Rand McKinney

unread,
Aug 19, 2015, 1:40:35 PM8/19/15
to LoopbackJS
You should be able to accomplish this if you use StrongLoop Process Manager and deploy / re-deploy your app, since you get zero-downtime updates.

Technically, this still restarts the app, but it does so in a way that it is not noticeable to users since it does a "rolling restart" of app worker processes.

Hope that helps.
Rand

jmls

unread,
Aug 19, 2015, 1:46:47 PM8/19/15
to LoopbackJS
thanks for that tip, but I'm actually running the app using gulp during a development process. 

What I am trying to do is when a model is added to the directory, add it to the models collection

is there an api to load a json + js into the models collection ? That would negate the reason for a restart

julian

jmls

unread,
Sep 28, 2015, 4:07:53 PM9/28/15
to LoopbackJS
*bump* again :)

I have 

var loopback = require('loopback');
x = loopback();

now, I have changed a model.json file and I need to have the modified model available *without* restarting the process

is this possible ?

jmls

unread,
Oct 6, 2015, 4:01:00 PM10/6/15
to LoopbackJS
ok, so I guess that no-one is using dynamic models in their apps :(

I am looking through some code, and find this 

var loopback = require('loopback');
var DataModel = loopback.PersistedModel || loopback.DataModel;


function loadModel(jsonFile) {
 
var modelDefinition = require(jsonFile);
 
return DataModel.extend(modelDefinition.name,
    modelDefinition
.properties,
   
{
      relations
: modelDefinition.relations
   
});
}


var UserIdentityModel = loadModel('./models/user-identity.json');
var UserCredentialModel = loadModel('./models/user-credential.json');
var ApplicationCredentialModel = loadModel(
 
'./models/application-credential.json');


exports
.UserIdentity = require('./models/user-identity')(UserIdentityModel);
exports
.UserCredential = require('./models/user-credential')(
 
UserCredentialModel);
exports
.ApplicationCredential = require('./models/application-credential')(
 
ApplicationCredentialModel);


exports
.UserIdentity.autoAttach = 'db';
exports
.UserCredential.autoAttach = 'db';
exports
.ApplicationCredential.autoAttach = 'db';


exports
.PassportConfigurator = require('./passport-configurator');



in loopback-component-passport, which seems to dynamically add a couple of models to loopback

Trouble is, I can find no documentation that describes this technique - so

  • is it valid ?
  • can I use the same techniques ?
  • does the autoattach actually work and add the model the the "db" database ?
I *really* would like to know the answers to the questions, it's so frustrating being on the tip of solving something to be confronted by the (lack of) documentation

If anyone could throw me a bone, I would appreciate it ;)

thanks

jmls

unread,
Oct 6, 2015, 4:09:33 PM10/6/15
to LoopbackJS
this is what I find _so_ frustrating with the docs - try and search for autoattach, and you get three results. All pdf files, all with changelog entries. Nothing at all about the actual property itself;


Reply all
Reply to author
Forward
0 new messages