I'd like to use sequelize to persist my objects in an existing DB. Until now I've been using manual queries with node-mysql but it's getting to cumbersome. I've read some of the documentation but I don't really understand how to use it for an existing DB. For instance the DB has a widgets table with PK id and then I have a properties table and each property has an FK pointing to the id of widgets. there are many properties that each point to the id of a particular widget. This seems like it should be easy yet I don't even know where to start because the documentation asumes I'm creating the tables within sequelize and not starting with an existing DB that's already populated with values. Does anyone have a link where I can see someone else doing a similar project?
Thank you for your reply. This being my first time using sequelize, I'm still a little lost.
so let's assume I'm looking at the example at http://docs.sequelizejs.com/en/latest/docs/getting-started/
when I get to:
var User = sequelize.define('user', {
firstName: {
type: Sequelize.STRING,
field: 'first_name' // Will result in an attribute that is firstName when user facing but first_name in the database
},
lastName: {
type: Sequelize.STRING
}
}, {
freezeTableName: true // Model tableName will be the same as the model name
});
User.sync({force: true}).then(function () {
// Table created
return User.create({
firstName: 'John',
lastName: 'Hancock'
});
});You simply exclude the sync() part.