sequelize.js

MariaDB connection with Sequelize

无人久伴 提交于 2020-01-21 15:22:36
问题 I have been checking for the connectivity of MariaDB, with Sequelize. const Sequelize = require('sequelize'); // Setting up database (MariaDB) connection const sequelize = new Sequelize('dbName', 'usr', 'pass', { host: 'localhost', dialect: 'mariadb' }); But I am getting the following error: /home/lt-196/api/node_modules/sequelize/lib/sequelize.js:236 throw new Error('The dialect ' + this.getDialect() + ' is not supported. Supported dialects: mssql, mysql, postgres, and sqlite.'); ^ Error:

Workflow for handling sequelize migrations and initialization?

心已入冬 提交于 2020-01-16 09:11:09
问题 I don’t get how sequelize migrations workflow works. I have a greenfield project, the database is designed using SQL scripts. We used sequelize auto to generate the models thereafter. I need to now generate a migrations file starting out, so I can run the CLI to run SQL queries to create new tables with columns etc for locally provisioned databases. There’s no 3rd party tools afaik to convert the SQL script I have into a Sequelize migrations file. I have to do this manually for 60 tables.

How to SELF JOIN using Sequelize in Node

拈花ヽ惹草 提交于 2020-01-15 11:42:30
问题 I'm using sequelize-cli for migrations and have researched different scenarios but there doesn't seem to be a definite solid answer as to how to self join. I want to have a join table called friendships which joins users and friends (which are essentially just users). More specifically trying to gain an understanding about the difference between "through" and "as" in this situation. 1) This is my friendship table. Getting tripped up on the second association. I have created two columns, one

How to SELF JOIN using Sequelize in Node

只愿长相守 提交于 2020-01-15 11:41:48
问题 I'm using sequelize-cli for migrations and have researched different scenarios but there doesn't seem to be a definite solid answer as to how to self join. I want to have a join table called friendships which joins users and friends (which are essentially just users). More specifically trying to gain an understanding about the difference between "through" and "as" in this situation. 1) This is my friendship table. Getting tripped up on the second association. I have created two columns, one

Sequelize: mapping between raw data and model

主宰稳场 提交于 2020-01-14 16:47:50
问题 I have some trouble to retrieve data from MySQL database using a raw query. The problem is the mapping between raw data and the instances of model defined in sequelize. In particular those fields that have underscored names in the database and camelcased in the model. I defined the Store model in this way: sequelize.define('stores', { id: { type: DataTypes.INTEGER(11), allowNull: false, primaryKey: true, autoIncrement: true }, ... postalCode: { type: DataTypes.STRING, field: 'postal_code', },

Sequelize: mapping between raw data and model

人走茶凉 提交于 2020-01-14 16:47:17
问题 I have some trouble to retrieve data from MySQL database using a raw query. The problem is the mapping between raw data and the instances of model defined in sequelize. In particular those fields that have underscored names in the database and camelcased in the model. I defined the Store model in this way: sequelize.define('stores', { id: { type: DataTypes.INTEGER(11), allowNull: false, primaryKey: true, autoIncrement: true }, ... postalCode: { type: DataTypes.STRING, field: 'postal_code', },

Update multiple rows in sequelize with different conditions

元气小坏坏 提交于 2020-01-14 10:33:27
问题 I'm trying to perform an update command with sequelize on rows in a postgres database. I need to be able to update multiple rows that have different conditions with the same value. For example, assume I have a user table that contains the following fields: ID First Name Last Name Gender Location createdAt Assume, I have 4 records in this table, I want to update records with ID - 1 and 4 with a new location say Nigeria. Something like this: SET field1 = 'foo' WHERE id = 1, SET field1 = 'bar'

How to perform a search with conditional where parameters using Sequelize

旧巷老猫 提交于 2020-01-14 09:33:03
问题 Usually whenever I write a search query for SQL, I do something similar to this: SELECT * FROM users u WHERE (@username IS NULL OR u.username like '%' + @username + '%') AND (@id IS NULL OR u.id = @id) Basically this simulates a conditional WHERE clause. We only want to compare @searchParam to the column if @searchParam was provided. Is there a way to replicate this using Sequelize? EDIT: Here is my best attempt which fails: models.user.findAll({ where: { username: searchParams.username ||

sequelize.query() returns same result twice

一个人想着一个人 提交于 2020-01-14 07:13:09
问题 I am working in nodejs project in that using sequelize for connecting mysql database. I am also using sequelize-values for getting raw data from Sequelize instances. I have written below code var Sequelize = require('sequelize'); require('sequelize-values')(Sequelize); var sequelizeObj = new Sequelize('mysql://root:@localhost/database'); sequelizeObj.authenticate().then(function (errors) { console.log(errors) }); sequelizeObj.query("SELECT * FROM `reports` WHERE `id` = 1200").then(function

How can I set schema for all models at once at connection time for Sequelize Postgres?

纵然是瞬间 提交于 2020-01-14 06:16:53
问题 I'm able to set schema for ad-hock queries with sequelize.query(` SET SCHEMA 'schema_for_client_name' `); I'm also able to set schema for individual models User.init( { userId: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, }, email: { type: DataTypes.STRING, allowNull: false, }, firstName: { type: DataTypes.STRING, allowNull: false, }, lastName: { type: DataTypes.STRING, allowNull: false, }, password: { type: DataTypes.STRING, allowNull: false, }, salt: { type: DataTypes