sequelize.js

SequelizeJS: Recursive include same model

夙愿已清 提交于 2019-12-11 04:53:57
问题 I want to fetch data from a Postgres database recursively including all associated models using SequelizeJS. GeoLocations table id | isoCode | name | parentId | type | updatedAt | deletedAt parentId holds the id of the parent GeoLocation. Model Associations GeoLocation.belongsTo(GeoLocation, { foreignKey: 'parentId', as: 'GeoLocation' }); Data explanation and example GeoLocation types and their relations: city -> subdivision -> country -> continent id: 552, name: Brooklyn, type: city,

unrecognized configuration parameter “autocommit” in PostgreSQL NodeJS

天涯浪子 提交于 2019-12-11 03:34:10
问题 {"message":"Err on translation create, for key blah blah blah ","name":"SequelizeDatabaseError","stack":"SequelizeDatabaseError: unrecognized configuration parameter \"autocommit\"\n at Query.module.exports.Query.formatError (/var/www/courses/courses.com.mm/dist/node_modules/sequelize/lib/dialects/postgres/query.js:361:16)\n at Query. (/var/www/courses/courses.com.mm/dist/node_modules/sequelize/lib/dialects/postgres/query.js:79:21)\n at emitOne (events.js:96:13)\n at Query.emit (events.js:188

How to use ES6 computed property names in node / iojs?

心已入冬 提交于 2019-12-11 03:33:27
问题 I am trying to write a tool that takes a CSV and dynamically generates a definition based on the header row? For example, a CSV with: Title(STRING), Description(TEXT) Title Example, Description Example ... the Sequelize docs specify, for example: var Entry = sequelize.define('Entry', { title: Sequelize.STRING, description: Sequelize.TEXT }) How could I write this definition so that it could be dynamically defined - so that title and the data type Sequelize.STRING could be dynamically

How to configure a one to many relationship in Sequelize?

我的梦境 提交于 2019-12-11 03:07:41
问题 I'm currently using Express with Sequelize + MySQL and was wondering what the best approach for me to solve this problem was. I apologise if this is a basic question as I'm pretty new to Sequelize and even SQL databases in general. I have a model User like so; export default db.define('User', { id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true, }, name: { type: Sequelize.STRING, allowNull: false, }, email: { type: Sequelize.STRING, allowNull: false, },

Node Sequelize migrations/models is it possible to share the same code?

ε祈祈猫儿з 提交于 2019-12-11 02:58:15
问题 I'm new at Sequelize so be patient. I started up a new project using Sequelize and migrations so I've got like this: migrations/20150210104840-create-my-user.js: "use strict"; module.exports = { up: function(migration, DataTypes, done) { migration.createTable("MyUsers", { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: DataTypes.INTEGER }, first_name: { type: DataTypes.STRING }, last_name: { type: DataTypes.STRING }, bio: { type: DataTypes.TEXT }, createdAt: { allowNull:

Using Node 'pg' library to connect to Amazon Redshift

孤街醉人 提交于 2019-12-11 02:54:20
问题 I am trying to connect my API to an instance of Redshift using the 'pg' library but I get the following error: Possibly unhandled error: SET TIME ZONE is not supported at Connection.parseE (/Users/henrylee/WebstormProjects/project-api/node_modules/pg/lib/connection.js:534:11) I know Redshift doesn't support the setting of timezone, but I don't really care about that. I can't seem to find any help about how to get past this issue, so any inout would be greatly appreciated. Thanks! 来源: https:/

Sequelize, Issue with filtering on the join model for belongsToMany associations

不羁的心 提交于 2019-12-11 01:59:19
问题 The Sequelize docs suggest that you can filter your query on join table attributes using the following params on the options object: [options.include[].through.where] I've tried to use this formulation in the code below and found that the filtering does not work. Model User and model Network are associated through the join table network-affiliations, which has additional attribute (boolean) 'confirmed'. I can't seem to write a query that returns only confirmed networks associated with a user.

Sequelize: Don't return password on Create

纵然是瞬间 提交于 2019-12-11 01:58:19
问题 When I create a new instance of my User with Sequelize, I get the full object returned from the database as a response to the Create. I'm trying to prevent Sequelize from returning the hashed password stored in my User table on create. exports.create = (payload, err, success) => { db.user.create(payload).then(success).catch(err); console.log('Created new user record.'); }; I tried using the exclude property, but the full object returns. exports.create = (payload, err, success) => { db.user

PassportJs Authentication Infinite Loop and Execute(default) query

寵の児 提交于 2019-12-11 01:43:17
问题 I am trying to build the authentication system using PassportJs and Sequelize. I made the registration system by myself, using Sequelize. I want to use PassportJS only for Login. It does not redirect me to the failureRedirect route, neither to the SuccessRedirect one, but when submitting the form it enters into an endless loop and in my console, the following message appears: Executing (default): SELECT `id`, `username`, `lastName`, `password`, `email`, `phone`, `createdAt`, `updatedAt` FROM

ExpressJS: Promises and Error Handling middleware

旧巷老猫 提交于 2019-12-11 01:13:37
问题 I have some error handling middleware defined and a route returning a promise. But when that promise gives an error, I have to manually append .catch(err => next(err)) after every promise. While its not a problem, isn't it sensible for ExpressJs to see if a route returns a promise and if so call the error handling middleware automatically. My current shortened code: // errorHandlers.js function sequelizeValidationError (err, req, res, next) { if (err.name && err.name ==