3

I am fairly new to Node but I am loving the tool. My only problem is when I want to have direct access to the database. I have a good experience with ruby on rails+postgres. Using rails console was very helpful when I was developing rails.

Is there some kind of equivalent I can use to have direct access to my database? I have uploaded my app to heroku so I would like something that I can run on heroku as well.

(I prefer not to use SQL, I am wondering if there is a sequelize console?)

1 Answer 1

1

Here is the way to do it:

node --experimental-repl-await

> models = require('./models'); 
> User = models.User; //however you load the model in your actual app this may vary
> await User.findAll(); //use await to avoid promise errors

TLDR

This gives you access to all of the models you have created and you can use the sequelize ORM commands like findAll, create etc.. just as you would in Rails active record.

Sequelize uses promises, so to run these properly in REPL you will want to use the --experimental-repl-await flag

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.