Tag: sequelize.js

Sequelize“SELECT * from tablename”查询

为什么下面的查询执行SELECT id, email, name FROM users AS users WHERE users.email = 'admin@admin.com'; 而不是SELECT * from users WHERE email = admin@admin.com ? http://docs.sequelizejs.com/en/latest/docs/querying/#where 文档指出,当我findAll()时它会运行一个SELECT *查询,但是在我的例子中它做了一些不同的事情。 这里缺less什么? 这是我的用户模型。 var user = sequelize.define('users', { id : { type : Sequelize.INTEGER, primaryKey : true, autoIncrement : true }, email : { type : Sequelize.STRING }, name : { type […]

护照js本地authentication使用sequelize

我正尝试使用护照本地身份validation与sequ​​elize。 当我提交login表单时,请求/响应周期永不结束,terminal中没有错误信息。 这里是我所有的代码: app.js var Sequelize = require('sequelize'), express = require('express'), bodyParser = require('body-parser'), cookieParser = require('cookie-parser'), passport = require('passport'), LocalStrategy = require('passport-local').Strategy, User = require('./models/users'); …….. and other imports….. //route import , model injection var auth = require('./routes/auth')(User); ………………….. app.use(session({ store: new RedisStore(), secret: 'keyboard cat', resave: false, saveUninitialized: false })); app.use(passport.initialize()); app.use(passport.session()); passport.serializeUser(function(user, […]

错误:“id”列中的空值违反了sequelize中的非空约束

我正在尝试将我的主键的数据types更改为sequelize中的string,并尝试使用upsert创build时出现以下错误。 error: SequelizeDatabaseError: null value in column "id" violates not-null constraint 这里是代码: id: { type: DataTypes.STRING, primaryKey: true, allowNull: true, autoIncrement: false, field: "id" } 我该如何做这项工作? 提前致谢。

Sequelize包括 – 不包括(删除)数据透视

我正在使用节点的Sequelize包。 我有一个典型的男人包括很多关系。 Item.findAll({ include: {model: Blah: as 'blahs'} }); 所有效果都很好,但是它会返回每个子项目上的透视数据集。 我不需要它。 有什么办法来禁用它或指定所需的透视字段?

在节点中validation用户时获取奇怪的输出

我创build了一个抓取用户email & password的函数,然后在数据库中运行一些检查来查看细节是否有效。 如果细节是有效的,那么用户将被parsing回API密钥。 但由于某种原因,一些函数被调用之前其他人,我得到undefined的variables,这是假设是返回userObj 。 在这个函数中,我添加了控制台日志0,1,2,4和5,所以当我调用函数时,你可以看到奇怪的输出。 我将在下面包含我的代码和控制台输出! 我使用sequalize模型,我知道他们正在返回正确的数据,因为我已经testing了它。 我也在使用promises 。 码: var auth = { login: function(req, res) { var email = req.body.email || ''; var password = req.body.password || ''; // If nothing parsed, return json obj if (email == '' || password == '') { console.log("1"); res.status(401); res.json({ "status": 401, "message": "Invalid […]

PassportJS(Local)与Sequelize和Express在序列化用户之后挂起

我正在尝试使用我在http://code.tutsplus.com/tutorials/authenticating-nodejs-applications-with-passport-cms-21619中find的教程进行login工作。 我修改了代码以使用Sequelize。 我能够validation用户名和密码,但序列化一个用户后,它redirect到的页面不会加载。 我想知道是否有什么我错过了。 我没有真正得到一个错误,但redirect到/testing/主页卡在悬而未决,并不断执行一个职位请求。 它似乎并没有运行req.isAuthenticated() Executing (default): SELECT "id", "email", "username", "password" FROM "users" AS "user" WHERE "user"."username" = 'user14' LIMIT 1; username and password matched serializing user: POST /test/login 302 377.738 ms – 64 Executing (default): SELECT "id", "email", "username", "password" FROM "users" AS "user" WHERE "user"."id" = 16; GET /test/home – – […]

无法使用npm安装* sequelize *

我无法使用npm安装sequelize 。 当我正在尝试得到以下错误。 我正在使用节点版本v5.4.1和npm版本3.3.12 。 谁能帮我。 谢谢

重新组合周期依赖关系

这是我的用户模型 'use strict'; var bcrypt = require('bcrypt'); module.exports = function(sequelize, DataTypes) { var User = sequelize.define('User', { email: { type: DataTypes.STRING, validate: { isEmail: true, notEmpty: true, notNull: false }, unique: true }, password: DataTypes.STRING, name: DataTypes.STRING, username: { type: DataTypes.STRING, unique: true }, admin: DataTypes.BOOLEAN, googleId: DataTypes.BOOLEAN }, { classMethods: { associate: function(models) { […]

续集BulkCreate错误

我想弄清楚如何使用我的jQuery字段值的bulkCreate方法。 目前我正在尝试传递数组中的字段的值,并期望每个值被parsing到一个新的logging,但它不会出现像这样的方式工作,因此我收到一个错误: Error during Post: SequelizeDatabaseError: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '['Test 1','Test 2','Test 3'],'6','2016-02-01 03:26:59','2016-02-01 03:26:59')' at line 1 这是因为我应该实际应用路线内的逻辑来处理不同的值? 我应该改变了jQuery? 查看文件(discoveryName是bulkCreate的字段): <!DOCTYPE html> <head> {{> head}} </head> <body> {{> navigation}} <div class="container"> […]

加重方言错误

我最近在安装lodash后遇到了一个奇怪的错误。 我不知道它是否对我的设置产生了任何影响,但是突然之间的sequelize会在mysql不支持的方言属性上抛出一个错误,并且无法读取property 'dialectName' of undefined 。 我不知道为什么发生这种情况,因为我一直在使用sequelize,而这一直没有出现。 运行节点v0.10.40 完整的错误: /sequelize/lib/sequelize.js:205 throw new Error('The dialect ' + this.getDialect() + ' is not supported. S ^ Error: The dialect mysql is not supported. Supported dialects: mariadb, mssql, mysql, postgres, and sqlite. (TypeError: Cannot read property 'dialectName' of undefined) at new Sequelize (/Users/user/Desktop/Projects/node/app-test/node_modules/sequelize/lib/sequelize.js:205:11) at Object.<anonymous> (/Users/user/Desktop/Projects/node/app-test/app/models/db-index.js:4:17) at Module._compile […]