Skip to content

Instantly share code, notes, and snippets.

@raevilman
Last active August 31, 2017 06:23
Show Gist options
  • Save raevilman/2549af100b212bc8170855743d36fd6f to your computer and use it in GitHub Desktop.
Save raevilman/2549af100b212bc8170855743d36fd6f to your computer and use it in GitHub Desktop.

Setup (env:Ubuntu)

  • apt-get install npm
  • apt install nodejs-legacy
  • npm install -g loopback-cli

Create Model
lb model

Delete a model
Delete /common/models/your-model.js and /common/models/your-model.json, then delete the lines referencing your model in /server/model-config.json.

Create Datasource
lb datasource


Files

SchemaUpdate.js (Place it in <loopback-project>/server/boot)
To update models schema back in db on every startup of the server


Postgre DB connector Guide
https://strongloop.com/strongblog/postgresql-node-js-apis-loopback-connector/


DynamoDb
https://github.com/tma-isbx/loopback-connector-dynamodb

npm install tma-isbx/loopback-connector-dynamodb

No model discovery both ways,,, but works if create "lb model" acc to definition of existing dynamoDb table

var async = require( 'async' );
module.exports = function( app, cb ) {
var datasources = Object.keys( app.dataSources );
async.eachSeries( datasources, function( dsName, cb ) {
var ds = app.dataSources[ dsName ];
ds.isActual( function( err, actual ) {
if ( err ) return cb( err );
if ( actual ) { console.log( 'datasource', dsName, 'is up to date' ); return
cb(); }
ds.autoupdate( function( err ) {
if ( err ) return cb( err );
console.log( 'datasource', dsName, 'updated' );
cb();
});
});
}, cb );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment