Skip to content

Instantly share code, notes, and snippets.

@mrowa44
Last active March 30, 2017 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrowa44/0f048f5b4802f066a81d9df07655ce06 to your computer and use it in GitHub Desktop.
Save mrowa44/0f048f5b4802f066a81d9df07655ce06 to your computer and use it in GitHub Desktop.
run with `node --inspect console.js`
'use strict';
const repl = require('repl');
// const request = require('supertest');
// const app = require('./app');
const models = require('./models');
const context = repl.start('node> ').context;
context.models = models;
// context.server = request(app);
// server.post('/api/users')
// .send({ username: 'Justyna', password: 'pass' })
// .end((err, res) => console.log(res.body))
Object.keys(models).forEach((name) => { context[name] = models[name]; });
// assign promise result to variable
// > assign('user', User.find({ where: { username: 'JaneDoe' } }))
context.assign = (name, promise) => {
promise.then((obj) => {
if (obj) {
obj.print = () => obj.dataValues;
obj.keys = () => Object.keys(obj);
obj.log = () => console.log(obj);
context[name] = obj;
}
});
};
console.log(`Available models: ${Object.keys(models).join(', ')}`);
debugger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment