sequelize.js

Sequelize Deprecated Error Message

喜你入骨 提交于 2019-12-09 04:39:50
问题 I'm very new to Node and I'm getting my head around how ORM and Sequelize works. I've been on the Sequelize website and copied the connection string and altered it to work with my database. When I execute the file, it seems to execute OK creating the table in my database however I get the error "String based operators are now deprecated.Please use Symbol based operators for better security ....node_modules/sequelize/lib/sequelize.js:236:13" I understand why the operators have been deprecated,

How to implement search feature using SequelizeJS?

﹥>﹥吖頭↗ 提交于 2019-12-09 03:34:11
问题 I have a Ticket model and a Comment model. The Ticket has a hasMany relationship to Comment model. I want to search tickets by a keyword. The keyword will be matched againts the subject attribute of the ticket model and the body attribute of the comment model. The code below doesn't work: var options = { where: { $or: [ { subject: { like: '%' + query + '%' }, }, { 'Comment.body': { like: '%' + query + '%' }, } ] }, include: [ { model: Comment }, ] }; Ticket.findAll(options); This is the error

passport.deserializeUser executing a DB (sequelize) command for each HTTP request

▼魔方 西西 提交于 2019-12-09 02:46:23
问题 I'm using sequelize as an ORM and passport.js (passport-local) for authentication. I noticed that every HTTP request is resulting in a separate database command. I started looking at the deserializeUser() function. When loading a single page, this is what I get: Executing: SELECT * FROM Users WHERE Users . id =1 LIMIT 1; Over and over and over! GET / 200 12ms - 780 Executing: SELECT * FROM Users WHERE Users . id =1 LIMIT 1; Executing: SELECT * FROM Users WHERE Users . id =1 LIMIT 1; Over and

Sequelize grouping by date, disregarding hours/minutes/seconds

人走茶凉 提交于 2019-12-08 18:03:16
问题 Hey so im trying to query from a database, using Sequelize (Node.js ORM for postgreSQL), im trying to group by date range, and keep a count of how many items where in that table. Right now the code i have is Task.findAll({ attributes: ['createdAt'], group: 'createdAt' }) But as you can see the grouping only takes into account the exact date (including seconds) so the grouping is actually pointless since no matter what there will be no overlapping items with the exact same second count. So i

Sequelize is returning integer as string

青春壹個敷衍的年華 提交于 2019-12-08 17:36:18
问题 I using nodejs v4 with sequelize, and I have a model like this: var Device = sequelize.define('Device', { id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true }, tenantId: { type: DataTypes.BIGINT, allowNull: false }, token: { type: DataTypes.STRING, allowNull: false } }, { tableName: 'devices' }); When I select a device by id the type of id is a string, exemple: Device.findById(9).then( function(result) { console.log(result.toJSON().id + 10); }); The output will be 910, rather

How do I install the sequelize.js binary?

余生颓废 提交于 2019-12-08 16:49:15
问题 I am referencing the sequelize.js documentation at: http://sequelizejs.com/documentation#migrations-the-binary After running 'sequelize -V', I receive: $ sequelize -V sequelize: command not found I have searched online and cannot find any references on how to install the binary 回答1: The CLI has moved to sequelize-cli : npm install -g sequelize-cli https://github.com/sequelize/cli 回答2: If you install locally, there are links to binaries at ./node_modules/.bin . This path applies to all your

Sequelize.js: join tables without associations

烂漫一生 提交于 2019-12-08 15:29:14
问题 Is there a way to join tables that don't have associations defined using include in sequelize? This is not a duplicate of this. I am talking about tables that are not associated at all but having columns that I want to join on. Example: select * from bank left outer join account on account.bank_name = bank.name The above query will return all records in table bank regardless of the existence of an account record where the specified constraints apply. In sequelize this would look something

Simple example of many-to-many relation using Sequelize

时间秒杀一切 提交于 2019-12-08 15:06:46
问题 I'm trying to build a simple example of many-to-many relation between tables using Sequelize. However, this seems to be way trickier than I expected. This is the code I have currently (the ./db.js file exports the Sequelize connection instance). const Sequelize = require("sequelize"); const sequelize = require("./db"); var Mentee = sequelize.define('mentee', { id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, name: { type: Sequelize.STRING } }); var Question = sequelize

TypeORM add custom column without losing object tree

房东的猫 提交于 2019-12-08 14:15:44
问题 following the docs if i want to add a custom column to the select eg. "sum(a.id) as count" i have to add ".getRaw...()", if i have a join (table A one to may table B) i'm losing the object tree ( [{id: 1, bs: [...]}] ) and the result is the raw sql list of repeated A rows ( [{id: 1, b_id: 1}, {id: 1, b_id: 2}] ) This is how i do it in sequelize const user = await User.findOne({ attributes: ['id', [Sequelize.fn('COUNT', Sequelize.col('id')), 'no_hats']], include: [ { model: UserKey, as: 'keys'

sequelize capitalize name before saving in database - instance hook

柔情痞子 提交于 2019-12-08 12:02:52
问题 I am new to sequelize and I am trying to capitalize the first letter of the name every time I create a new "Rider" so it looks capitalized on my table. I haven't been able to do it: this is my model: const db = require("./db"); const Sequelize = require("sequelize"); //(w / WSL ranking, Last tournament won, Country, favorite wave, current board). const Rider = db.define("rider", { name: { type: Sequelize.STRING, allowNull: false }, country: Sequelize.STRING, wsa: { type: Sequelize.INTEGER,