As there are often use cases in which it is just easier to execute raw / already prepared SQL queries, you can utilize the function `sequelize.query`.
As there are often use cases in which it is just easier to execute raw / already prepared SQL queries, you can utilize the function `sequelize.query`.
By default the function will return two arguments - a results array, and an object containing metadata (affected rows etc.). Note that since this is a raw query, the metadata (property names etc.) is dialect specific.
By default the function will return two arguments - a results array, and an object containing metadata (affected rows etc.). Note that since this is a raw query, the metadata (property names etc.) is dialect specific. Some dialects return the metadata "within" the results object (as properties on an array). However, two arguments will always be returned, but for MSSQL and MySQL it will be two references to the same object.
```js
```js
sequelize.query("UPDATE users SET y = 42 WHERE x = 12").spread(function(results,metadata){
sequelize.query("UPDATE users SET y = 42 WHERE x = 12").spread(function(results,metadata){
...
@@ -29,20 +29,20 @@ sequelize.query('SELECT * FROM projects', Projects).then(function(projects){
...
@@ -29,20 +29,20 @@ sequelize.query('SELECT * FROM projects', Projects).then(function(projects){
```
```
# Replacements
# Replacements
Replacements in a query can be done in two different ways, either using named parameters (starting with `:`), or unnamed, represented by a `?`. Replacements can be passed in the options object.
Replacements in a query can be done in two different ways, either using named parameters (starting with `:`), or unnamed, represented by a `?`. Replacements are passed in the options object.
* If an array is passed, `?` will be replaced in the order that they appear in the array
* If an array is passed, `?` will be replaced in the order that they appear in the array
* If an object is passed, `:key` will be replaced with the keys from that object. If the object contains keys not found in the query or vice verca, an exception will be thrown.
* If an object is passed, `:key` will be replaced with the keys from that object. If the object contains keys not found in the query or vice verca, an exception will be thrown.
```js
```js
sequelize.query('SELECT * FROM projects WHERE status = ?',
sequelize.query('SELECT * FROM projects WHERE status = ?',