|
|
@ -14,7 +14,7 @@ Postgres.prototype._myClass = Postgres; |
|
|
|
Postgres.prototype._arrayAggFunctionName = 'array_agg'; |
|
|
|
|
|
|
|
Postgres.prototype.getQuery = function(queryNode) { |
|
|
|
//passed in a table, not a query
|
|
|
|
// passed in a table, not a query
|
|
|
|
if(queryNode instanceof Table) { |
|
|
|
queryNode = queryNode.select(queryNode.star()); |
|
|
|
} |
|
|
@ -78,7 +78,7 @@ Postgres.prototype.visitSelect = function(select) { |
|
|
|
|
|
|
|
Postgres.prototype.visitInsert = function(insert) { |
|
|
|
var self = this; |
|
|
|
//don't use table.column for inserts
|
|
|
|
// don't use table.column for inserts
|
|
|
|
this._visitedInsert = true; |
|
|
|
|
|
|
|
var paramNodes = insert.getParameters() |
|
|
@ -104,9 +104,9 @@ Postgres.prototype.visitInsert = function(insert) { |
|
|
|
}; |
|
|
|
|
|
|
|
Postgres.prototype.visitUpdate = function(update) { |
|
|
|
//don't auto-generate from clause
|
|
|
|
// don't auto-generate from clause
|
|
|
|
var params = []; |
|
|
|
/*jshint boss: true */ |
|
|
|
/* jshint boss: true */ |
|
|
|
for(var i = 0, node; node = update.nodes[i]; i++) { |
|
|
|
this._visitingUpdateTargetColumn = true; |
|
|
|
var target_col = this.visit(node); |
|
|
@ -129,7 +129,7 @@ Postgres.prototype.visitDelete = function() { |
|
|
|
|
|
|
|
Postgres.prototype.visitCreate = function(create) { |
|
|
|
this._visitingCreate = true; |
|
|
|
//don't auto-generate from clause
|
|
|
|
// don't auto-generate from clause
|
|
|
|
var table = this._queryNode.table; |
|
|
|
var col_nodes = table.columns.map(function(col) { return col.toNode(); }); |
|
|
|
|
|
|
@ -142,7 +142,7 @@ Postgres.prototype.visitCreate = function(create) { |
|
|
|
}; |
|
|
|
|
|
|
|
Postgres.prototype.visitDrop = function(drop) { |
|
|
|
//don't auto-generate from clause
|
|
|
|
// don't auto-generate from clause
|
|
|
|
var result = ['DROP TABLE']; |
|
|
|
result = result.concat(drop.nodes.map(this.visit.bind(this))); |
|
|
|
result.push(this.visit(this._queryNode.table.toNode())); |
|
|
@ -151,7 +151,7 @@ Postgres.prototype.visitDrop = function(drop) { |
|
|
|
|
|
|
|
Postgres.prototype.visitAlter = function(alter) { |
|
|
|
this._visitingAlter = true; |
|
|
|
//don't auto-generate from clause
|
|
|
|
// don't auto-generate from clause
|
|
|
|
var table = this._queryNode.table; |
|
|
|
// TODO: col_nodes is unused?
|
|
|
|
var col_nodes = table.columns.map(function(col) { return col.toNode(); }); |
|
|
@ -221,8 +221,8 @@ Postgres.prototype.visitUnary = function(unary) { |
|
|
|
|
|
|
|
Postgres.prototype.visitQuery = function(queryNode) { |
|
|
|
this._queryNode = queryNode; |
|
|
|
//need to sort the top level query nodes on visitation priority
|
|
|
|
//so select/insert/update/delete comes before from comes before where
|
|
|
|
// need to sort the top level query nodes on visitation priority
|
|
|
|
// so select/insert/update/delete comes before from comes before where
|
|
|
|
var sortedNodes = []; |
|
|
|
var missingFrom = true; |
|
|
|
var hasFrom = false; |
|
|
@ -257,19 +257,19 @@ Postgres.prototype.visitQuery = function(queryNode) { |
|
|
|
} |
|
|
|
} |
|
|
|
if(!actions.length) { |
|
|
|
//if no actions are given, guess it's a select
|
|
|
|
// if no actions are given, guess it's a select
|
|
|
|
actions.push(new Select().add('*')); |
|
|
|
} |
|
|
|
if(missingFrom) { |
|
|
|
targets.push(new From().add(queryNode.table)); |
|
|
|
} |
|
|
|
//lazy-man sorting
|
|
|
|
// lazy-man sorting
|
|
|
|
sortedNodes = actions.concat(targets).concat(filters); |
|
|
|
for(i = 0; i < sortedNodes.length; i++) { |
|
|
|
var res = this.visit(sortedNodes[i]); |
|
|
|
this.output = this.output.concat(res); |
|
|
|
} |
|
|
|
//implicit 'from'
|
|
|
|
// implicit 'from'
|
|
|
|
return this.output; |
|
|
|
}; |
|
|
|
|
|
|
|