Sketch of using map table + map index if present for zxystream.

This commit is contained in:
Young Hahn
2014-12-10 03:07:32 -05:00
parent bdfa6a65a4
commit 067db2ce70
3 changed files with 55 additions and 1 deletions
+11 -1
View File
@@ -28,7 +28,17 @@ function ZXYStream(source, options) {
ZXYStream.prototype._read = function() {
var stream = this;
this.source._db.all('SELECT zoom_level AS z, tile_column AS x, tile_row AS y FROM tiles LIMIT ' + this.batch + ' OFFSET ' + this.offset, function(err, rows) {
// Check for the existence of a map table that is indexed.
if (!stream.table) {
return this.source._db.get("select count(1) as count from sqlite_master where type = 'index' and tbl_name = 'map';", function(err, row) {
if (err) return stream.emit('error', err);
stream.table = row.count === 1 ? 'map' : 'tiles';
return stream._read();
});
}
this.source._db.all('SELECT zoom_level AS z, tile_column AS x, tile_row AS y FROM ' + this.table + ' LIMIT ' + this.batch + ' OFFSET ' + this.offset, function(err, rows) {
if (err && err.code === 'SQLITE_ERROR' && /no such table/.test(err.message)) return stream.push(null);
if (err) return stream.emit('error', err);
if (!rows.length) return stream.push(null);