Last active
April 19, 2017 18:11
-
-
Save rttomlinson/58b883539444fb24a18c4de1858a9e6d to your computer and use it in GitHub Desktop.
package.json for databases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // package.json | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1", | |
| // Usual commands now namespaced | |
| "sql:migrate:undo": "npm run sql db:migrate:undo:all", | |
| "sql:migrate": "npm run sql db:migrate", | |
| "sql:seed:undo": "npm run sql db:seed:undo:all", | |
| "sql:seed": "npm run sql db:seed:all", | |
| // Shorter convenience command to run | |
| // migrations and seeds | |
| "sql:s": "npm run sql:migrate:undo && npm run sql:migrate && npm run sql:seed", | |
| // MongoDB specific seeding | |
| "mg:seed": "node seeds/mongoose", | |
| // Same stuff here | |
| "console": "node repl.js", | |
| "c": "node repl.js", | |
| "sql": "./node_modules/sequelize-cli/bin/sequelize" | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // repl.js | |
| var mongoose = require('mongoose'); | |
| var repl = require('repl').start({}); | |
| var models = { | |
| mongoose: require('./models/mongoose'), | |
| sequelize: require('./models/sequelize') | |
| }; | |
| var helpers = require('./helpers'); | |
| require('./mongo')().then(() => { | |
| repl.context.models = models; | |
| repl.context.helpers = helpers; | |
| // ---------------------------------------- | |
| // Helpers | |
| // ---------------------------------------- | |
| Object.keys(helpers).forEach((key) => { | |
| repl.context[key] = helpers[key]; | |
| }); | |
| // ---------------------------------------- | |
| // Mongoose | |
| // ---------------------------------------- | |
| Object.keys(models.mongoose).forEach((modelName) => { | |
| repl.context[modelName] = mongoose.model(modelName); | |
| }); | |
| // ---------------------------------------- | |
| // Sequelize | |
| // ---------------------------------------- | |
| Object.keys(models.sequelize).forEach((modelName) => { | |
| repl.context[modelName] = models.sequelize[modelName]; | |
| }); | |
| // ---------------------------------------- | |
| // Logging | |
| // ---------------------------------------- | |
| repl.context.lg = (data) => { | |
| if (Array.isArray(data)) { | |
| if (data.length && data[0].dataValues) { | |
| data = data.map(item => item.dataValues); | |
| } | |
| } | |
| console.log(data); | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment