Tag: sequelize.js

exception的通用捕获版本?

我有一个sequelize数据库validation数据并抛出错误。 我知道我可以做这样的事情来捕捉和输出我的错误: User.build() .catch(Sequelize.ValidationError, function (err) { // respond with validation errors return res.status(422).send(err.errors); }) .catch(function (err) { // every other error return res.status(400).send({ message: err.message }); 但我不想把它添加到每一个请求,是否有一些通用的方法来捕捉这些错误?

在协会中添加帮助

所有,下面的附加是一个SQL查询,我用它作为一个原始查询在续集中,它工作正常。 现在我正在尝试将它设置为mixin关联,但不能这样做。 有没有通过帮助文件,但不能完全掌握的细节。 也许它只是我。 无论如何,下面附加的是我试图返工的查询。 如果有人能抛出一些指针或有一些样本来帮助我重做这个,会感激不尽? 提前致谢。 select cust.*, cust_role.id, cust_role.rolename, role.roletype from customer cust, customer_roles cust_role, roles role where cust.id = cust_role.user and cust_role.role = role.id and cust.id like '0123456' //customerId 表关系 customer_roles has a foreign key to both roles and customer tables customer to customer_roles (1 to many), customer_roles to roles (many to […]

多租户(SAAS)使用nodejs集合

我正在尝试使用nodejs和postgres构build一个多租户(/ Software as a service),并将其作为ORMinheritance。 由于安全原因,我决定为每个客户端使用单独的数据库,而不是单个数据库,而所有表都有额外的列。 我取得了这个结果,但是性能并不好,因为我必须根据每个数据库(几乎每个请求)初始化每个数据库的模型。 有没有更好的方法来做到这一点? 我在遗漏了什么东西吗?

将嵌套关系序列化,有多个“作者”的“post”?

我正在用Postgres学习Sequelize。 我怎样才能使“post”有多个作者? 我目前每个post只有一个作者。 我尝试使用Post.hasMany(Person)但我不知道如何填写下面的同步声明中的数据,因为我从教程中复制它…这是我第一次使用数据库。 import Sequelize from 'sequelize'; import _ from 'lodash'; import Faker from 'faker'; const Conn = new Sequelize( 'test_db', 'postgres', 'postgres', { dialect: 'postgres', host: 'localhost' } ); const Person = Conn.define('person', { firstName: { type: Sequelize.STRING, allowNull: false }, lastName: { type: Sequelize.STRING, allowNull: false } }); const Post = Conn.define('post', […]

用户注册使用护照+ express + mysql + sequelize

我正在尝试使用Passport,MySql,NodeJS和Sequelize构build用户注册api。 我面对的唯一问题是,当一个用户注册一次,他试图用相同的电子邮件重新注册用户被抛出一个401未经授权的错误,而不是用户对象。 当我试图debugging相同的响应,我从服务器得到这个[对象SequelizeInstance:用户]。 这些文件已经在下面提到。 多谢提前一吨!!! Passport.js文件: var LocalStrategy = require('passport-local').Strategy; var mysql = require('mysql'); var Model = require('../models/models.js'); // expose this function to our app using module.exports module.exports = function(passport) { // ========================================================================= // passport session setup ================================================== // ========================================================================= // required for persistent login sessions // passport needs ability to serialize and unserialize users […]

Sequelize.js不能在关联表字段的WHERE子句中生成条件

我有下面的代码在Node.js与sequ​​elize.js模块 // association Users belongs to Companies Users.belongsTo(Companies, { foreignKey: 'company_id', }); // default conditions var conditions = {deleted: '0'}; var companyConditions = {deleted: '0'}; // custom conditions parameters conditions['$or'] = {first_name: {'$like': '%' + req.query.search + '%'}, last_name: {'$like': '%' + req.query.search + '%'}, email: {'$like': '%' + req.query.search + '%'}}; companyConditions['$or'] = {name: […]

有人可以帮我删除我的Db Sequelizelogging吗?

我已经尝试下面的代码看到它的趋势,但我不知道为什么它不工作 Posts.destroy({ where: { createdAt: { isAfter: "2016-09-11" } } }) 我想摧毁24小时后的post,所以我修改了上面的内容 Posts.destroy({ where: { createdAt: { isAfter: new Date() } } }) 我想在今天之后摧毁所有的post然后我去看看留下的post,但我仍然看到现有的post

Node.js:如何在Sequelize中使用Postgres存储过程?

我最近学习了这个强大的ORM的所有规格,如迁移表,定义模式,定义模型,关联,插入等。 我特别的问题是如何pipe理Postgres存储过程(SP)的续集? 我为我的服务器使用Node.js。

我使用Sequelize的数据库模型不做迁移

我有两个模型: user.js的 'use strict' module.exports = function(sequelize, DataTypes) { var User = sequelize.define('User', { gid: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, email: { type: DataTypes.STRING, allowNull: false }, password: { type: DataTypes.STRING, allowNull: false }, newsletters: { type: 'NUMERIC', allowNull: false, defaultValue: '1' }, status: { type: 'NUMERIC', allowNull: false, defaultValue: […]

从那里获得返回结果

我有以下代码: var ORM = require('../helpers/mysql_orm'); var log = require('../helpers/logger'); function UserModel() { this.User = ORM.define('User', { }, { tableName: 'User', timestamps: false, }); } UserModel.prototype.findOneByCredinitals = function (creditinals) { this.User.findOne({ attributes:['username','id'], where: { username:creditinals.principal, password:creditinals.creditinal} }) .then(function(user) { console.log("inside then function"+user); return user; }) // console.log(result); }, UserModel.prototype.findAllByLimit = function(req,res) { } module.exports= new UserModel; […]