将所有查询设置为 raw = true sequelize [英] Setting all queries to raw = true sequelize

查看:23
本文介绍了将所有查询设置为 raw = true sequelize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢使用 sequelize 作为我的节点应用程序的 ORM,但是现在,当您查询时它们默认传递 DAO 对象时,我有点恼火.如何始终将原始选项设置为 true?

I really like using sequelize as my ORM for my node application, but right now, I am kind of irritated when they are passing DAO objects by default when you query. How can I set the raw option to true all the time?

推荐答案

根据 文档 :

如果您不提供 SQL 以外的其他参数,raw 将被假定为 true,sequelize 不会尝试对查询结果进行任何格式化.

If you do not provide other arguments than the SQL, raw will be assumed to the true, and sequelize will not try to do any formatting to the results of the query.

话虽如此:

Sequelize 对象有一个 [options.query={}] 可选参数来设置 sequelize.query 的默认选项.来源

The Sequelize object has a [options.query={}] optional parameter to set default options for sequelize.query. Source

您应该能够使用:

var sequelize = new Sequelize('database', 'username', 'password', {query:{raw:true}})

这篇关于将所有查询设置为 raw = true sequelize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆