Giter Club home page Giter Club logo

sequelize-erd's People

Contributors

alamantus avatar dependabot[bot] avatar f26401004 avatar rzorzal avatar wwmoraes avatar zekenie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sequelize-erd's Issues

Error: Cannot convert undefined or null to object

Just setup sequelize-erd with this line in my package.json sequelize-erd --source ./app/models/ --destination ./erd.svg and get this error when I try a npm run erd

> [email protected] erd /Users/bastien/Documents/WWW/express-mvc
> sequelize-erd --source ./app/models/ --destination ./erd.svg

/Users/bastien/Documents/WWW/express-mvc/node_modules/sequelize-erd/index.js:31
  const models = Object.values(db.models);
                        ^

TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at module.exports.path (/Users/bastien/Documents/WWW/express-mvc/node_modules/sequelize-erd/index.js:31:25)
    at Object.<anonymous> (/Users/bastien/Documents/WWW/express-mvc/node_modules/sequelize-erd/bin/generate:14:13)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] erd: `sequelize-erd --source ./app/models/ --destination ./erd.svg`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] erd script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bastien/.npm/_logs/2017-08-08T20_18_45_782Z-debug.log

Error: Cannot find module 'sequelize'

I installed the package and added it to my package.json scripts.

running returns

$ npm run erd

> [email protected] erd /Users/harrymoreno/programming/foo
> sequelize-erd --source ./src/node_modules/lib/database.js --destination ./erd.svg

module.js:442
    throw err;
    ^

Error: Cannot find module 'sequelize'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/harrymoreno/programming/foo/src/node_modules/lib/database.js:1:79)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)

npm ERR! Darwin 16.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "erd"
npm ERR! node v6.2.0
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] erd: `sequelize-erd --source ./src/node_modules/lib/database.js --destination ./erd.svg`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] erd script 'sequelize-erd --source ./src/node_modules/lib/database.js --destination ./erd.svg'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the effigy package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     sequelize-erd --source ./src/node_modules/lib/database.js --destination ./erd.svg
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs effigy
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls effigy
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/harrymoreno/programming/foo/npm-debug.log

thoughts?

API example incomplete

Your API example is incomplete. It doesn't have the require('sequelize') and where does sequelizeErd come from?

const db = new Sequelize();
// Import DB models here

const svg = sequelizeErd({ source: db });
writeFileSync('./erd.svg', svg);

// Writes erd.svg to local path with SVG file from your Sequelize models

Publish latest commit to NPM

A fix was implemented in the most recent commit #b0ca825 that is not published to NPM, making the package not work with new versions of Sequelize.

Can you please publish the changes so installing it via NPM works properly?

TypeError: Cannot convert undefined or null to object

I get the following error when running:

$ npm run erd
/Users/n/Desktop/repos/api/node_modules/sequelize-erd/index.js:40
        ? Object.values(model.attributes)
                 ^

TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at modelTemplate (/Users/nico/Desktop/repos/charge-api/node_modules/sequelize-erd/index.js:40:18)
    at modelsArr.filter.map.model (/Users/nico/Desktop/repos/charge-api/node_modules/sequelize-erd/index.js:137:21)
    at Array.map (<anonymous>)
    at generateDot (/Users/nico/Desktop/repos/charge-api/node_modules/sequelize-erd/index.js:137:8)
    at module.exports (/Users/nico/Desktop/repos/charge-api/node_modules/sequelize-erd/index.js:165:15)
    at Object.<anonymous> (/Users/nico/Desktop/repos/charge-api/node_modules/sequelize-erd/bin/generate:21:1)
    at Module._compile (internal/modules/cjs/loader.js:799:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:810:10)
    at Module.load (internal/modules/cjs/loader.js:666:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:606:12)
    at Function.Module._load (internal/modules/cjs/loader.js:598:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:862:12)
    at internal/main/run_main_module.js:21:11

package.json:

"erd": "sequelize-erd --source ./tasks/generateERD/index.js --destination ./erd.svg"

tasks/generateERD/index.js:

const { sequelize } = require('../../models/index.js')

// Require our models. Running each module registers the model into sequelize
// so any other part of the application can simply call sequelize.model('User')
// to get access to the User model.
require('../../models')

module.exports = sequelize

models/index.js:

'use strict'

const fs = require('fs')
const path = require('path')
const Sequelize = require('sequelize')
const basename = path.basename(__filename)
const env = process.env.NODE_ENV || 'development'
const config = require(path.join(__dirname, '/../config/config.js'))[env]
const db = {}

let sequelize
if (config.use_env_variable) {
  sequelize = new Sequelize(process.env[config.use_env_variable], config)
} else {
  sequelize = new Sequelize(
    config.database,
    config.username,
    config.password,
    config
  )
}

fs.readdirSync(__dirname)
  .filter(file => {
    return (
      file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js'
    )
  })
  .forEach(file => {
    const model = sequelize['import'](path.join(__dirname, file))
    db[model.name] = model
  })

Object.keys(db).forEach(modelName => {
  if (db[modelName].associate) {
    db[modelName].associate(db)
  }
})

// sequelize.sync()

db.sequelize = sequelize
db.Sequelize = Sequelize

module.exports = { db, sequelize, Sequelize }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.