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?
Asked
Active
Viewed 3.6k times
15
-
2your title says : set raw = true, and your question asks how to set raw= false... – xShirase Oct 07 '14 at 04:36
2 Answers
25
According to the doc :
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.
That being said :
The Sequelize object has a [options.query={}] optional parameter to set default options for sequelize.query. Source
You should be able to use :
var sequelize = new Sequelize('database', 'username', 'password', {query:{raw:true}})

xShirase
- 11,975
- 4
- 53
- 85
-
Wow, that was very helpful, I have one problem though, when I use create, there are still DAO objects, the query raw: true helped when I used find but it won't affect when I use create. Sample code: `Model.create({name: 'test'}, {options: raw: true})` – mateeyow Oct 07 '14 at 04:36
-
-
https://github.com/sequelize/sequelize/wiki/API-Reference-Model#createvalues-options----promiseinstance – xShirase Oct 07 '14 at 04:53
-
You edited your comment... `Model.create({name: 'test'}, {raw: true})` should work – xShirase Oct 07 '14 at 04:54
-
well, the question : "Setting all queries to raw = true" is answered, maybe ask a specific question for the Model.create(). are you sure `Model.create({name: 'test'}, {raw: true})` doesn't work? – xShirase Oct 07 '14 at 04:57
-
Just be careful to note that this bypasses sequelize modal transformations. E.g TINYINT will be returned as 0/1 with raw as opposed to true/false – Kyle Roach Jan 26 '23 at 15:14
3
For create you can use this:
Model.create(modelObject)
.then((resultEntity) => {
const dataObj = resultEntity.get({plain:true})
}
Check this out: Set raw = true on Sequelize Model.create

Mon
- 1,010
- 1
- 11
- 19