Setting all queries to raw = true sequelize

后端 未结 2 555
不思量自难忘°
不思量自难忘° 2020-12-09 19:21

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

相关标签:
2条回答
  • 2020-12-09 20:07

    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}})
    
    0 讨论(0)
  • 2020-12-09 20:09

    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

    0 讨论(0)
提交回复
热议问题