Skip to content

Commit

Permalink
Merge pull request #2579 from stevage/autosubquery
Browse files Browse the repository at this point in the history
Automatically wrap and unwrap bare "select" postgis statements.
  • Loading branch information
Komzpa committed Oct 25, 2016
2 parents 5ca74c8 + 106c96f commit 2251a6d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions views/Layer.bones
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ view.prototype.render = function() {
}
}
}
var table = this.$('textarea[name="Datasource.table"]');
// hide tilemill-generated subquery names
if (table.val()) {
table.val(table.val().replace(/^\((\s*select[\s\S]*)\) as _subquery$/i, "$1"));
}
return this;
};

Expand Down Expand Up @@ -291,6 +296,8 @@ view.prototype.save = function(e) {
} else {
attr.srs = attr.srs || '';
}


// Advanced options.
var regular = _(['type', 'file','table', 'host', 'port', 'user',
'password', 'dbname', 'extent', 'key_field', 'geometry_field',
Expand Down Expand Up @@ -346,6 +353,11 @@ view.prototype.save = function(e) {
attr.id = (attr.id || this.autoname(attr.Datasource.file||attr.Datasource.table)).replace('#','');
attr['class'] = (attr['class'] || '').replace('.','');

if (attr.Datasource.table) {
// wrap bare SELECT statements, even multi-line, in an identifiable subquery label which can be removed later.
attr.Datasource.table = attr.Datasource.table.replace(/^ *(select\s[\s\S]*from[\s\S]*)$/i,"($1) as _subquery");
}

$(this.el).addClass('loading').addClass('restartable');
var error = _(function(m, e) {
if ($(this.el).hasClass('restarting')) return false;
Expand Down

0 comments on commit 2251a6d

Please sign in to comment.