Guest User

Untitled

a guest
Jun 22nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. const Sequelize = require('sequelize');
  2. const sequelize = new Sequelize('db', 'user', 'password', {
  3. host: '0.0.0.0',
  4. port: '8306',
  5. dialect: 'mysql',
  6. operatorsAliases: false,
  7. pool: {
  8. max: 5,
  9. min: 0,
  10. acquire: 30000,
  11. idle: 10000
  12. },
  13. define: {
  14. timestamps: false
  15. }
  16. });
  17.  
  18. sequelize
  19. .authenticate()
  20. .then(() => {
  21. console.log('Connection has been established successfully.');
  22. })
  23. .catch(err => {
  24. console.error('Unable to connect to the database:', err);
  25. });
  26.  
  27. const Channel = sequelize.define('brands', {
  28. brandid: {
  29. type: Sequelize.INTEGER,
  30. primaryKey: true
  31. },
  32. name: {
  33. type: Sequelize.STRING
  34. }
  35. });
  36.  
  37. const Brief = sequelize.define('briefs', {
  38. briefid: {
  39. type: Sequelize.INTEGER,
  40. primaryKey: true
  41. },
  42. name: {
  43. type: Sequelize.STRING
  44. },
  45. brand: {
  46. type: Sequelize.INTEGER,
  47. references: {
  48. model: Channel,
  49. key: 'brandid'
  50. }
  51. }
  52. });
  53.  
  54. Channel.findAll({
  55. include: [{
  56. model: Brief
  57. }]
  58. //[{ all: true, nested: true }]
  59. })
  60. .then(channels => {
  61. channels.forEach(function(channel) {
  62. console.log(channel.name);
  63. });
  64. })
Add Comment
Please, Sign In to add comment