sequelize .query code example

Example 1: sequelize query result

sequelize.query("UPDATE users SET y = 42 WHERE x = 12").spread(function(results,
  	metadata) {
  // Results will be an empty array and metadata will contain the number of 
  // affected rows.
})

/* In cases where you don't need to access the metadata you can pass in a query 
type to tell sequelize how to format the results. For example, for a simple 
select query you could do: */

sequelize.query("SELECT * FROM `users`", { type: sequelize.QueryTypes.SELECT})
  .then(function(users) {
    // We don't need spread here, since only the results will be returned for 
    // select queries
  })

Example 2: sequelize documentation

const { Sequelize, Model, DataTypes } = require('sequelize');
const sequelize = new Sequelize('sqlite::memory:');

class User extends Model {}
User.init({
  username: DataTypes.STRING,
  birthday: DataTypes.DATE
}, { sequelize, modelName: 'user' });

sequelize.sync()
  .then(() => User.create({
    username: 'janedoe',
    birthday: new Date(1980, 6, 20)
  }))
  .then(jane => {
    console.log(jane.toJSON());
  });