sequelize/sequelize — pull request #651 by optilude (2013-05-27 14:13:20+00:00)
Title: Quoting sanity

This change does three interrelated things:

* Provide a way to invoke dialect-specific quoting of identifiers (tables, columns, etc) and escaping of values through the QueryInterface. This makes it easier to write portable code that generates SQL strings. The relevant methods are `quoteIdentifier()` (tables, columns); `quoteIdentifiers()` (dotted names of the same) and `escape()`, all on the `QueryInterface`, delegating to the dialect's `QueryGenerator`.

* Clean up the umpteen different ways in which things were quoted previously, to use these two new functions. Where functions like `addQuotes() existed previously, they've been kept to not introduce a breaking change, but for compatibility only.

* Provide a Sequelize-wide option `quoteIdentifiers`, which defaults to `true`. If false, identifiers in Postgres will not be quoted. See #643 for why this is important. This is implemented by

Note that for the query generator to be able to read `options` in a function like `quoteIdentifier()`, we need to invoke methods from `this` rather than from the `QueryGenerator` class. The (Jasmine) test setup for the query generator tests used to use a shortcut for setting options that re-bound `this` to a dummy object using `apply()`. This broke the tests. However, the real code in `QueryInterface` did not do this, so the tests have been adjusted to be consistent.