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

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

问题描述

我真的很喜欢将sequelize用作我的节点应用程序的ORM,但是现在,当默认情况下在查询时它们传递DAO对象时,我有点恼火.如何始终将raw选项设置为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天全站免登陆