sequelize.js

SequelizeJS: How to include association (join) across multiple databases without using raw query

三世轮回 提交于 2021-01-27 14:35:35
问题 Suppose, there is "Account" table in DB "A", and there is "ConversationHistory" table in DB "B". My pseudo initialized script is: // Connection Script var db1 = new Sequelize("A", user, password) var db2 = new Sequelize("B", user, password) // Association Account.hasMany(ConversationHistory, {foreignKey: "sender_id", as: "conversations", constraints: false}) ConversationHistory.belongsTo(Account, {foreignKey: "sender_id", as: "sender", constraints: false}); // But when I use include in

MySQL with Sequelize: ER_BAD_DB_ERROR: Unknown database

ぃ、小莉子 提交于 2021-01-27 05:43:10
问题 I am following a tutorial and below is the code: var Sequelize = require('sequelize') var sequelize = new Sequelize('basic-mysql-database.mysql', 'root', 'password', { 'dialect': 'mysql', 'host': "localhost", "port": "3306" }); var Todo = sequelize.define('todo', { description: { type: Sequelize.STRING }, completed: { type: Sequelize.BOOLEAN } }) sequelize.sync().then(function(){ console.log('Everything is synced') Todo.create({ description: 'Walking my dog', completed: false }).then(function

MySQL with Sequelize: ER_BAD_DB_ERROR: Unknown database

偶尔善良 提交于 2021-01-27 05:42:30
问题 I am following a tutorial and below is the code: var Sequelize = require('sequelize') var sequelize = new Sequelize('basic-mysql-database.mysql', 'root', 'password', { 'dialect': 'mysql', 'host': "localhost", "port": "3306" }); var Todo = sequelize.define('todo', { description: { type: Sequelize.STRING }, completed: { type: Sequelize.BOOLEAN } }) sequelize.sync().then(function(){ console.log('Everything is synced') Todo.create({ description: 'Walking my dog', completed: false }).then(function

How can users like and unlike each others post using sequelize postgres nodejs?

蹲街弑〆低调 提交于 2021-01-26 03:02:32
问题 I am trying to implement that users can like each others post. Here is my Likes model: const Likes = db.define("Likes", { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, PostId: { type: Sequelize.INTEGER, references: { model: "Post", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, userId: { type: Sequelize.INTEGER, references: { model: "User", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, createdAt: { allowNull: false, type:

How can users like and unlike each others post using sequelize postgres nodejs?

試著忘記壹切 提交于 2021-01-26 03:01:19
问题 I am trying to implement that users can like each others post. Here is my Likes model: const Likes = db.define("Likes", { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, PostId: { type: Sequelize.INTEGER, references: { model: "Post", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, userId: { type: Sequelize.INTEGER, references: { model: "User", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, createdAt: { allowNull: false, type:

How can users like and unlike each others post using sequelize postgres nodejs?

醉酒当歌 提交于 2021-01-26 03:01:18
问题 I am trying to implement that users can like each others post. Here is my Likes model: const Likes = db.define("Likes", { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, PostId: { type: Sequelize.INTEGER, references: { model: "Post", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, userId: { type: Sequelize.INTEGER, references: { model: "User", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, createdAt: { allowNull: false, type:

How to load attributes from associated models with sequelize.js

倖福魔咒の 提交于 2021-01-24 09:35:08
问题 I am simplify the current project with two models. Kiosk model module.exports = function(sequelize, DataTypes) { return sequelize.define('kiosk', { id: { type: DataTypes.BIGINT, allowNull: false, primaryKey: true, autoIncrement: true }, name: { type: DataTypes.STRING(150), allowNull: false }, }, { tableName: 'kiosk', timestamps: false, underscored: true }); }; Receipt model module.exports = function(sequelize, DataTypes) { return sequelize.define('receipt', { id: { type: DataTypes.STRING(255)

How to load attributes from associated models with sequelize.js

末鹿安然 提交于 2021-01-24 09:33:26
问题 I am simplify the current project with two models. Kiosk model module.exports = function(sequelize, DataTypes) { return sequelize.define('kiosk', { id: { type: DataTypes.BIGINT, allowNull: false, primaryKey: true, autoIncrement: true }, name: { type: DataTypes.STRING(150), allowNull: false }, }, { tableName: 'kiosk', timestamps: false, underscored: true }); }; Receipt model module.exports = function(sequelize, DataTypes) { return sequelize.define('receipt', { id: { type: DataTypes.STRING(255)

ERROR: Please install mysql2 package manually

China☆狼群 提交于 2021-01-22 04:08:49
问题 When using the sequalize db:migrate command I am getting the following error. Looking at some of the previous comments on similar issues people said it is a dependency issue but whenever I run npm install mysql2 or npm install -g mysql2 I get the same error. larry@DESKTOP-NSSNPRR:/mnt/c/Users/larry/Desktop/node/AAF-NodeJS$ sequelize db:migrate Sequelize CLI [Node: 10.1.0, CLI: 4.0.0, ORM: 4.37.10] (node:2241) ExperimentalWarning: The fs.promises API is experimental Loaded configuration file

ERROR: Please install mysql2 package manually

断了今生、忘了曾经 提交于 2021-01-22 04:07:49
问题 When using the sequalize db:migrate command I am getting the following error. Looking at some of the previous comments on similar issues people said it is a dependency issue but whenever I run npm install mysql2 or npm install -g mysql2 I get the same error. larry@DESKTOP-NSSNPRR:/mnt/c/Users/larry/Desktop/node/AAF-NodeJS$ sequelize db:migrate Sequelize CLI [Node: 10.1.0, CLI: 4.0.0, ORM: 4.37.10] (node:2241) ExperimentalWarning: The fs.promises API is experimental Loaded configuration file