diff --git a/lib/mbtiles.js b/lib/mbtiles.js index 1919b1e..4de9f71 100644 --- a/lib/mbtiles.js +++ b/lib/mbtiles.js @@ -96,24 +96,18 @@ MBTiles.findID = function(filepath, id, callback) { MBTiles.prototype._exists = function(table, callback) { if (typeof callback !== 'function') callback = noop; - if (this._schema) { - return callback(null, this._schema.indexOf(table) !== -1); - } else { - this._db.all( - 'SELECT name FROM sqlite_master WHERE type IN (?, ?)', - 'table', - 'view', - function(err, rows) { - if (err) return callback(err); - this._schema = rows.map(function(r) { return r.name }); - this._exists(table, callback); - }.bind(this) - ); - } + if (this._schema) return callback(null, this._schema.indexOf(table) !== -1); + + var sql = 'SELECT name FROM sqlite_master WHERE type IN ("table", "view")'; + var mbtiles = this; + this._db.all(sql, function(err, rows) { + if (err) return callback(err); + mbtiles._schema = rows.map(function(r) { return r.name }); + mbtiles._exists(table, callback); + }); }; // DB integrity check. -// // - @param {Function(err)} callback MBTiles.prototype._integrity = function(callback) { if (typeof callback !== 'function') callback = noop;