Skip to content

Instantly share code, notes, and snippets.

@vincentdesmares
Last active September 19, 2017 17:17
Show Gist options
  • Save vincentdesmares/2a76573cff21c0fcbc7ec7e70646903a to your computer and use it in GitHub Desktop.
Save vincentdesmares/2a76573cff21c0fcbc7ec7e70646903a to your computer and use it in GitHub Desktop.
Sequelize example
const Sequelize = require('sequelize'),
epilogue = require('epilogue'),
express = require('express'),
bodyParser = require('body-parser');
// Define your models with Sequelize
// This is equivalent to defining Doctrine entities
let database = new Sequelize('database', 'root', 'password');
let User = database.define('User', {
username: Sequelize.STRING
});
// Create an Express server
let app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Plug Epilogue into Express
epilogue.initialize({
app: app,
sequelize: database
});
// Configure a REST resource endpoint with Epilogue
let userResource = epilogue.resource({
model: User,
endpoints: ['/users', '/users/:id']
});
// And that's it, GET/POST and DELETE will be available for your user entity.
app.listen(() => {
console.log('Server started!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment