diff --git a/bin/mbcheck b/bin/mbcheck index 6cb1163..f8d5966 100755 --- a/bin/mbcheck +++ b/bin/mbcheck @@ -23,29 +23,29 @@ if (argv.help || argv._.length === 0) { Step( function() { mbtiles = new MBTiles(argv._[0], this); }, - function() { mbtiles.integrity(this); }, + function() { mbtiles._integrity(this); }, function(err) { if (err) throw err; - mbtiles.exists('tiles', function(err, exists) { + mbtiles._exists('tiles', function(err, exists) { if (!exists) throw new Error('`tiles` table does not exist.'); this(); }.bind(this)); }, function(err) { if (err) throw err; - mbtiles.exists('metadata', function(err, exists) { + mbtiles._exists('metadata', function(err, exists) { if (!exists) throw new Error('`metadata` table does not exist.'); this(); }.bind(this)); }, function(err) { if (err) throw err; - mbtiles.metadata('name', this.parallel()); - mbtiles.metadata('type', this.parallel()); - mbtiles.metadata('desciption', this.parallel()); - mbtiles.metadata('version', this.parallel()); - mbtiles.metadata('format', this.parallel()); - mbtiles.metadata('bounds', this.parallel()); + mbtiles._metadata('name', this.parallel()); + mbtiles._metadata('type', this.parallel()); + mbtiles._metadata('desciption', this.parallel()); + mbtiles._metadata('version', this.parallel()); + mbtiles._metadata('format', this.parallel()); + mbtiles._metadata('bounds', this.parallel()); }, function(err, name, type, description, version, format, bounds) { console.warn('Metadata'); @@ -64,7 +64,7 @@ Step( Step( function() { var group = this.group(), - query = mbtiles.db.prepare( + query = mbtiles._db.prepare( 'SELECT zoom_level AS zoom, ' + 'COUNT(zoom_level) AS count ' + 'FROM tiles ' + @@ -95,7 +95,7 @@ Step( Step( function() { var group = this.group(), - query = mbtiles.db.prepare( + query = mbtiles._db.prepare( 'SELECT MAX(tile_column) AS maxx, ' + 'MIN(tile_column) AS minx, ' + 'MAX(tile_row) AS maxy, ' + @@ -113,7 +113,7 @@ Step( if (err) throw err; var group = this.group(), - query = mbtiles.db.prepare( + query = mbtiles._db.prepare( 'SELECT zoom_level AS zoom, ' + 'COUNT(zoom_level) AS count, ' + '? AS expected ' + diff --git a/bin/mbcompact b/bin/mbcompact index 9101421..0bd8f9f 100755 --- a/bin/mbcompact +++ b/bin/mbcompact @@ -28,7 +28,7 @@ Step( function() { mbtiles = new MBTiles(filename, this); }, function(err) { if (err) throw err; - mbtiles.db.all('SELECT name, type ' + mbtiles._db.all('SELECT name, type ' + 'FROM sqlite_master ' + 'WHERE type IN (?, ?)', 'table', @@ -47,13 +47,13 @@ Step( }, function(err) { if (err) throw err; - mbtiles.setup(this); + mbtiles._setup(this); }, function(err) { if (err) throw err; - mbtiles.db.get('SELECT COUNT(*) AS total FROM tiles', this.parallel()); - mbtiles.db.run('PRAGMA locking_mode=EXCLUSIVE', this.parallel()); - mbtiles.db.run('PRAGMA journal_mode=TRUNCATE', this.parallel()); + mbtiles._db.get('SELECT COUNT(*) AS total FROM tiles', this.parallel()); + mbtiles._db.run('PRAGMA locking_mode=EXCLUSIVE', this.parallel()); + mbtiles._db.run('PRAGMA journal_mode=TRUNCATE', this.parallel()); }, function(err, row) { if (err) throw err; @@ -64,7 +64,7 @@ Step( var done = this; var doit = function(limit, offset) { process.nextTick(function() { - mbtiles.db + mbtiles._db .prepare('SELECT tile_data AS tile_data, zoom_level AS z, tile_column AS x, tile_row AS y FROM tiles LIMIT ? OFFSET ?') .all(limit, offset, function(err, rows) { var images = []; @@ -92,8 +92,8 @@ Step( } Step( function() { - mbtiles.insert('images', images, this.parallel()); - mbtiles.insert('map', map, this.parallel()); + mbtiles._insert('images', images, this.parallel()); + mbtiles._insert('map', map, this.parallel()); }, function(err) { if (err) throw err; @@ -123,17 +123,17 @@ Step( }, function(err) { if (err) throw err; - mbtiles.db.run('DROP TABLE tiles', this); + mbtiles._db.run('DROP TABLE tiles', this); }, function(err) { if (err) throw err; - mbtiles.db.run('CREATE VIEW IF NOT EXISTS tiles AS ' + mbtiles._db.run('CREATE VIEW IF NOT EXISTS tiles AS ' + 'SELECT map.zoom_level AS zoom_level, ' + 'map.tile_column AS tile_column, ' + 'map.tile_row AS tile_row, ' + 'images.tile_data AS tile_data ' + 'FROM map JOIN images ON images.tile_id = map.tile_id;', this.parallel()); - mbtiles.db.run('VACUUM', this.parallel()); + mbtiles._db.run('VACUUM', this.parallel()); }, function(err) { if (err) throw err; diff --git a/bin/mbpipe b/bin/mbpipe index 5efbd3f..f06d8b2 100755 --- a/bin/mbpipe +++ b/bin/mbpipe @@ -36,22 +36,22 @@ Step( function(err) { if (err) throw err; Step( - function() { mbtiles.db.run('PRAGMA synchronous=0', this); }, - function() { mbtiles.db.run('PRAGMA locking_mode=EXCLUSIVE', this); }, - function() { mbtiles.db.run('PRAGMA journal_mode=TRUNCATE', this); }, + function() { mbtiles._db.run('PRAGMA synchronous=0', this); }, + function() { mbtiles._db.run('PRAGMA locking_mode=EXCLUSIVE', this); }, + function() { mbtiles._db.run('PRAGMA journal_mode=TRUNCATE', this); }, this ); }, function(err) { if (err) throw err; - mbtiles.exists('tiles', function(err, exists) { + mbtiles._exists('tiles', function(err, exists) { if (exists) table = 'tiles'; this(); }.bind(this)); }, function(err) { if (err) throw err; - mbtiles.exists('images', function(err, exists) { + mbtiles._exists('images', function(err, exists) { if (exists) table = 'images'; this(); }.bind(this)); @@ -59,7 +59,7 @@ Step( function(err) { if (err) throw err; if (!table) throw new Error('No usable image table found.'); - mbtiles.db.get('SELECT COUNT(tile_data) AS total FROM ' + table, function(err, row) { + mbtiles._db.get('SELECT COUNT(tile_data) AS total FROM ' + table, function(err, row) { total = row.total; this(); }.bind(this)); @@ -73,8 +73,8 @@ Step( var doit = function(table, limit, offset) { process.nextTick(function() { var query = table === 'images' - ? mbtiles.db.prepare('SELECT tile_data AS tile_data, tile_id AS id FROM images ORDER BY tile_id ASC LIMIT ? OFFSET ?') - : mbtiles.db.prepare('SELECT tile_data AS tile_data, zoom_level AS z, tile_column AS x, tile_row AS y FROM tiles ORDER BY z, x, y LIMIT ? OFFSET ?'); + ? mbtiles._db.prepare('SELECT tile_data AS tile_data, tile_id AS id FROM images ORDER BY tile_id ASC LIMIT ? OFFSET ?') + : mbtiles._db.prepare('SELECT tile_data AS tile_data, zoom_level AS z, tile_column AS x, tile_row AS y FROM tiles ORDER BY z, x, y LIMIT ? OFFSET ?'); query.all(limit, offset, function(err, rows) { Step( function() { @@ -95,14 +95,14 @@ Step( child.on('exit', function(code) { if (code) return callback(null, null); if (table === 'images') { - mbtiles.db.run( + mbtiles._db.run( 'INSERT OR REPLACE INTO images (tile_id, tile_data) VALUES(?, ?)', row.id, row.piped, callback ); } else { - mbtiles.db.run( + mbtiles._db.run( 'INSERT OR REPLACE INTO tiles (zoom_level, tile_column, tile_row, tile_data) VALUES(?, ?, ?, ?)', row.z, row.x, @@ -126,7 +126,7 @@ Step( if (rows.length === limit) { doit(table, limit, offset + limit); } else { - mbtiles.db.run('VACUUM', function() { + mbtiles._db.run('VACUUM', function() { sys.print('\n'); console.warn('Pipe complete.'); done();