不要怂,就是干,撸起袖子干!

Commit 934bfa09 by joshm

Add pg schema specific test sets

Bulk queries do not completely work with schemas, so
the test fixture may have issues.

all but the last 3 tests of findAll.ph.schema.test.js should pass
1 parent 50fea7b0
......@@ -638,7 +638,7 @@ module.exports = (function() {
if (options.include) {
var generateJoinQueries = function(include, parentTable) {
var table = include.daoFactory.tableName
var table = include.daoFactory.getTableName()
, as = include.as
, joinQueryItem = ""
, joinQueries = {
......@@ -672,7 +672,7 @@ module.exports = (function() {
}
if (through) {
var throughTable = through.daoFactory.tableName
var throughTable = through.daoFactory.getTableName()
, throughAs = as + "." + through.as
, throughAttributes = through.attributes.map(function(attr) {
return self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(throughAs + "." + attr)
......@@ -699,7 +699,7 @@ module.exports = (function() {
// Filter statement for left side of through
// Used by both join and subquery where
sourceJoinOn = self.quoteIdentifier(tableSource) + "." + self.quoteIdentifier(attrSource) + " = "
sourceJoinOn = self.quoteTable(tableSource) + "." + self.quoteIdentifier(attrSource) + " = "
sourceJoinOn += self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(identSource)
// Filter statement for right side of through
......@@ -708,7 +708,7 @@ module.exports = (function() {
targetJoinOn += self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(identTarget)
// Generate join SQL for left side of through
joinQueryItem += joinType + self.quoteIdentifier(throughTable) + " AS " + self.quoteIdentifier(throughAs) + " ON "
joinQueryItem += joinType + self.quoteTable(throughTable) + " AS " + self.quoteIdentifier(throughAs) + " ON "
joinQueryItem += sourceJoinOn
// Generate join SQL for right side of through
......@@ -724,7 +724,7 @@ module.exports = (function() {
// Creating the as-is where for the subQuery, checks that the required association exists
var _where = "(";
_where += "SELECT "+self.quoteIdentifier(identSource)+" FROM " + self.quoteIdentifier(throughTable) + " AS " + self.quoteIdentifier(throughAs);
_where += "SELECT "+self.quoteIdentifier(identSource)+" FROM " + self.quoteTable(throughTable) + " AS " + self.quoteIdentifier(throughAs);
_where += joinType + self.quoteTable(table) + " AS " + self.quoteIdentifier(as) + " ON "+targetJoinOn;
_where += " WHERE " + sourceJoinOn + " AND " + targetWhere + " LIMIT 1"
_where += ")";
......@@ -876,9 +876,33 @@ module.exports = (function() {
// If using subQuery, select attributes from wrapped subQuery and join out join tables
if (subQuery) {
//the subquery "AS" uses the tableName at the front of the SELECT (out of the subquery)
//as the "AS", when this is the case, force quoting on the mainAttributes "options.table"
//that will be used in the "AS".
var asTable = options.table
var aliasAttrs = mainAttributes[0].split('.')
if(aliasAttrs.length > 1) {
var baseName = aliasAttrs[0]+'.'+aliasAttrs[1]
//here is the match from subquery to mainAttributes
if(baseName === options.table) {
var aliasAttrs = mainAttributes[0].split('.')
var remainingVals = Utils._.rest(aliasAttrs, 2)
//only add back the rest if it exists
if(remainingVals.length) {
mainAttributes[0] = self.quoteIdentifier(baseName, true)+'.'+remainingVals.join('.')
} else {
mainAttributes[0] = self.quoteIdentifier(baseName, true)
}
//quote the "as"
asTable = self.quoteIdentifier(options.table, true)
}
}
query = "SELECT " + mainAttributes.join(', ') + " FROM ("
query += subQueryItems.join('')
query += ") AS "+options.table
query += ") AS "+asTable
query += mainJoinQueries.join('')
query += mainQueryItems.join('')
} else {
......
......@@ -279,7 +279,7 @@ module.exports = (function() {
}.bind(this))
var replacements = {
table: this.quoteIdentifiers(tableName)
table: this.quoteTable(tableName)
, attributes: allAttributes.map(function(attr){
return this.quoteIdentifier(attr)
}.bind(this)).join(",")
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!