Sequelize findOne()和SQL Server的问题(Trouble with Sequelize findOne() and SQL Server)
我是Sequelize的新手,并且正在尝试运行基本查询以在我的数据库中查找模型的第一个实例。 我的模型
user.js
:var Sequelize = require('sequelize'); var sequelize = new Sequelize('Northwind', 'username', 'password', { host: 'localhost', port: 1433, dialect: 'mssql' }); var User = sequelize.define('Employees', { Name: Sequelize.STRING, createdAt: false, updatedAt: false }); module.exports = User;
以及调用代码的
Express.js
应用程序中的文件api.js
:router.route('/posts') .get(function (req, res) { var user; User.find({ where: { Name: 'matt' } }).then(function (user) { console.log('found'); }, function(err){ console.log(err); }); res.send({ message: 'Test string' }); });
我使用了值“Matt”,因为我知道它在
Employees
表中。 但是,在执行时,我收到的错误似乎表明Sequelize正在尝试从我知道在Employees
表中不存在的列中SELECT
,如[id]
[createdAt]
,[updatedAt]
,[updatedAt]
。 我相信它与findOne()
命令有一个(default)
执行,但我不知道如何配置。任何指针将不胜感激!
I am new to Sequelize and was trying to run a basic query to find the first instance of model in my database. My model
user.js
:var Sequelize = require('sequelize'); var sequelize = new Sequelize('Northwind', 'username', 'password', { host: 'localhost', port: 1433, dialect: 'mssql' }); var User = sequelize.define('Employees', { Name: Sequelize.STRING, createdAt: false, updatedAt: false }); module.exports = User;
And the the file,
api.js
, in myExpress.js
application where the code is called:router.route('/posts') .get(function (req, res) { var user; User.find({ where: { Name: 'matt' } }).then(function (user) { console.log('found'); }, function(err){ console.log(err); }); res.send({ message: 'Test string' }); });
I used the value "Matt" for I know it is in the table
Employees
. However, upon executing, I receive errors about which seem to indicate that Sequelize is trying toSELECT
from columns I know do not exist in theEmployees
table like[id]
,[createdAt]
,[updatedAt]
. I believe it has to do with thefindOne()
command having a(default)
execution, but I am not sure how to config.Any pointers would be much appreciated!
原文:https://stackoverflow.com/questions/39105230
最满意答案
定义(易失性)环境变量并在CMD中执行命令:
set "ENV=development" gulp
在一行中:
set "ENV=development" & gulp
定义(易失性)环境变量并在PowerShell中执行命令:
$env:ENV = 'development' & gulp
在一行中:
$env:ENV = 'development'; & gulp
Defining a (volatile) environment variable and executing a command in CMD:
set "ENV=development" gulp
In one line:
set "ENV=development" & gulp
Defining a (volatile) environment variable and executing a command in PowerShell:
$env:ENV = 'development' & gulp
In one line:
$env:ENV = 'development'; & gulp
相关问答
更多-
您需要运行“node node_modules \ gulp \ bin \ gulp.js install”,只需在其前面添加“node”命令,并参阅下面的链接以获取更多信息 在Windows 10上运行gulp时出错 我无法发表评论,但是在派生版本库之后运行“npm install”,要安装package.json“dependencies,dev-dependencies”? Gulp需要在全球范围内安装,并且也在您当前的工作目录中。 运行下面的代码来全局安装Gulp,另一个安装库依赖项。 npm i ...
-
gulp.task('set-dev-node-env', function() { return process.env.NODE_ENV = 'development'; }); gulp.task('set-prod-node-env', function() { return process.env.NODE_ENV = 'production'; }); 使用它像: gulp.task('build_for_prod', ['set-prod-node-env'], funct ...
-
如何在Gulp中使用Node Environment Variables?(How to use Node Environment Variables inside Gulp?)[2022-06-04]
你混淆了一些条款: Gulp是一个构建工具,它只在构建时运行(compile,concat,minify),与运行时无关。 Angular是一个客户端框架,因此它无法访问底层系统,因此您无法使用angular获取系统变量 node是服务器,它可以访问系统变量,因此您需要做的就是从角度到节点发出ajax请求,并让节点为您提供所需的变量。 You are confusing some terms: Gulp is a build tool, it only runs at build time (compile ... -
定义(易失性)环境变量并在CMD中执行命令: set "ENV=development" gulp 在一行中: set "ENV=development" & gulp 定义(易失性)环境变量并在PowerShell中执行命令: $env:ENV = 'development' & gulp 在一行中: $env:ENV = 'development'; & gulp Defining a (volatile) environment variable and executing a command ...
-
GULP:gulp没有定义(GULP: gulp is not defined)[2022-12-07]
你只需要在本地安装并需要gulp ,你可能只在全球安装 在命令行 cd&& npm install --save-dev gulp 在你的gulpfile.js中 var gulp = require('gulp'); 这是与命令行依赖关系(全局安装的)不同的依赖关系。 更具体地说,它是相同的NPM包,但命令行程序通常会从NPM包中的不同入口点执行代码,然后返回需要('X')的代码。 如果我们转到Github的Gulp项目中的package.json文件,它会告诉我们整 ... -
你需要安装并需要gulp-compass ,而不是compass 。 You need to install and require gulp-compass, not compass.
-
您必须在本地安装一个gulp到该文件夹。 使用以下命令。 npm install gulp 如果没有修复,请尝试安装 npm安装gulp-cli -g You must locally install gulp to that folder. Use the following command: npm install gulp if it is not fixed, try to install it globally: npm install gulp-cli -g
-
如果文件可以是json,那么你可以.. var file = require('custom.json'); if (file.option) { ... } If the file can be a json, you can just.. var file = require('custom.json'); if (file.option) { ... }
-
WSL不支持慢速/预览/生产环中的FS通知系统调用。 在Fast环中,它支持跟踪WSL内部的更改。 Devs承诺支持跟踪Windows中所做的更改将很快添加。 相关链接: GitHub问题 UserVoice票证 WSL doesn't support FS notify syscalls in Slow/Preview/Production rings. In the Fast ring, it supports tracking changes made inside WSL. Devs promise ...
-
Bash只允许环境变量在一个bash会话期间存在。 当你输入 export sweet_param=5 只要bash打开, sweet_param存在。 关上你的外壳, sweet_param消失了。 gulp-shell每行接受一个命令,但是对于每一行,它都会启动另一个bash:open bash >> execute line >> terminate bash >> next。 因此,在你拥有的每一行之后,所有先前设置的参数都消失了。 尝试: gulp.task('run-me', shell.tas ...