将所有查询设置为 raw = true sequelize [英] Setting all queries to 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屋!