Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Sequelize = require('sequelize');
- const sequelize = new Sequelize('db', 'user', 'password', {
- host: '0.0.0.0',
- port: '8306',
- dialect: 'mysql',
- operatorsAliases: false,
- pool: {
- max: 5,
- min: 0,
- acquire: 30000,
- idle: 10000
- },
- define: {
- timestamps: false
- }
- });
- sequelize
- .authenticate()
- .then(() => {
- console.log('Connection has been established successfully.');
- })
- .catch(err => {
- console.error('Unable to connect to the database:', err);
- });
- const Channel = sequelize.define('brands', {
- brandid: {
- type: Sequelize.INTEGER,
- primaryKey: true
- },
- name: {
- type: Sequelize.STRING
- }
- });
- const Brief = sequelize.define('briefs', {
- briefid: {
- type: Sequelize.INTEGER,
- primaryKey: true
- },
- name: {
- type: Sequelize.STRING
- },
- brand: {
- type: Sequelize.INTEGER,
- references: {
- model: Channel,
- key: 'brandid'
- }
- }
- });
- Channel.findAll({
- include: [{
- model: Brief
- }]
- //[{ all: true, nested: true }]
- })
- .then(channels => {
- channels.forEach(function(channel) {
- console.log(channel.name);
- });
- })
Add Comment
Please, Sign In to add comment