Skip to content

Instantly share code, notes, and snippets.

@maxbeatty
Created July 18, 2017 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxbeatty/984efb63534aeddc50e59f5858875d73 to your computer and use it in GitHub Desktop.
Save maxbeatty/984efb63534aeddc50e59f5858875d73 to your computer and use it in GitHub Desktop.
zeit/micro w/ sequelize
const Sequelize = require("sequelize");
const sequelize = new Sequelize(
process.env.DB_NAME,
process.env.DB_USER,
process.env.DB_PASS,
{
host: process.env.DB_HOST,
dialect: "mysql"
}
);
sequelize.define("user", {
id: {
type: DataTypes.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
isEmail: true
}
}
});
sequelize.sync(); // yes, this is an async operation :<
module.exports = async (req, res) => {
const randomUserId = Math.round(Math.random() * 100);
const user = await sequelize.model("user").findById(randomUserId);
return user.get("email");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment